gpt4 book ai didi

mysql - 不应用任何顺序检索 mysql 数据

转载 作者:行者123 更新时间:2023-11-29 23:23:06 25 4
gpt4 key购买 nike

我有一个名为 actions 的表主键为 action_id ,我正在从该表中检索数据,并传递我自己的命令 action_id例如

$actionIds = array(5,9,10,21,3,18,4);
$actionsTb = Engine_Api::_()->getDbtable('actions','activity');

$postSelect = $actionsTb->select()
->where('action_id IN(?)', $actionIds)
->where('type = ?', 'status')
;

现在的问题是,当我按升序返回结果时,例如( 3,4,5,9,10,18,21 ),但我想要的结果顺序是因为我传递了操作 ID 意味着不不想对结果应用任何顺序。请帮我。您也可以通过简单的查询进行回复。

最佳答案

既然你使用php,为什么不使用循环动态创建where子句这里是代码

$where = "action_id IN(";

for($x=0; $x<count($actionIds); $x++)
{

// code for adding comma in every end of id
if($x==count($actionIds)-1)
{
// found the last data in array add closing parenthesis in IN funtion
$where.=$actionIds[$x].")";

}
else
{
$where.=$actionIds[$x].",";
}
}

首先测试输出回显

echo $where; //so i think the result is "action_id IN(5,9,10,21,3,18,4)"

这是完整的代码

$actionIds = array(5,9,10,21,3,18,4);
$where = "action_id IN(";

for($x=0; $x<count($actionIds); $x++)
{

// code for adding comma in every end of id
if($x==count($actionIds)-1)
{
$where.=$actionIds[$x].",";
}
else
{
// add closing parenthesis in IN funtion
$where.=$actionIds[$x].")";
}
}

$actionsTb = Engine_Api::_()->getDbtable('actions','activity');

$postSelect = $actionsTb->select()
->where($where)
->where('type = ?', 'status')
;

关于mysql - 不应用任何顺序检索 mysql 数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27163179/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com