PHP
$wall_id = 5;
$pull_adj_id = $connectDB->prepare("(SELECT walls.wall_id FROM walls WHERE
walls.wall_id > ? ORDER BY walls.wall_id ASC LIMIT 1)
UNION
(SELECT walls.wall_id FROM walls WHERE
walls.wall_id < ? ORDER BY walls.wall_id DESC LIMIT 1);");
$pull_adj_ids->bind_param('ii', $wall_id, $wall_id);
$pull_adj_ids->execute();
$adj_result = $pull_adj_ids->get_result();
$adj_data = $adj_result->fetch_array();
print_r($adj_data);
输出:Array ( [0] => 5 [wall_id] => 5 )
关于我之前的问题,我尝试构建我的查询以从表中提取大于和小于id,但查询只返回一个值。但是当我尝试在phpMyAdmin中运行相同的查询时,它会提供6
和4
。
答案 0 :(得分:1)
当您只提取一个
时,您的查询会返回2行答案 1 :(得分:0)
你必须循环你的结果。
试试这个
$pull_adj_ids->execute();
$pull_adj_ids->store_result();
$adj_result = $pull_adj_ids->bind_result($wall_id);
while ($adj_data = $adj_result->fetch()){
echo $wall_id.'<br />';
}