我试图通过从另一个数据库中获取的ID数组查询mysql数据库来选择多行,但我似乎没有运气,我检索ID然后将它们存储在这样的数组中; $ array = results => followerID => “1”,“2”。 我似乎无法遍历嵌套数组结果,也无法使用它们来搜索数据库并显示返回的所有结果。
更新:
$ ids var_dump:
array(3) {
[0]=>
array(1) {
["followingID"]=>
string(1) "3"
}
[1]=>
array(1) {
["followingID"]=>
string(1) "8"
}
[2]=>
array(1) {
["followingID"]=>
string(1) "7"
}
}
代码:
$user = $_REQUEST['userID'];
$userNID = $_REQUEST['user'];
$check = query("SELECT followingID FROM user_follows WHERE followerID='%s'", $user);
if (count($check['result'])>0) {
$ids = $check['result'];
$id_implode = implode( "', '", $ids);
echo '{"implode":'.$id_implode.'}';
$get = query("SELECT username, firstname, lastname FROM user_accounts WHERE userID IN ('%s')", $id_implode);
if (!$get['error']) {
class Emp {
public $success = "";
public $result = "";
public $error = "";
}
$e = new Emp();
$e->success = 1;
$e->result = $get['result'];
$e->error = "No problems";
echo json_encode($e);
} else {
class Emp {
public $success = "";
public $error = "";
}
$e = new Emp();
$e->success = 0;
$e->error = "Connection Error";
echo json_encode($e);
exit();
}
}
?>
答案 0 :(得分:1)
好的,感谢您的更新,这可以帮助您修复代码:
在设置$ ids变量
后放置此项$id_holder = array();
foreach($ids as $key=>$value){
array_push($id_holder,$value['followingID']);
}
$id_holder = implode(',',$id_holder);
然后是你的其余代码。