基本上,我从table1中提取一个ID,使用该ID在table2中查找站点ID,然后需要在数组中使用站点ID,内爆并在table3中查询站点名称.我无法正确内爆数组,首先我遇到错误,然后使用while循环.
使用while循环,输出仅表示:数组
$MysqLi = MysqLi_connect("server","login","pass","db");
$sql = "SELECT MarketID FROM marketdates WHERE Date = '2010-04-04 00:00:00' AND VenueID = '2'";
$result = MysqLi_query($MysqLi,$sql) or die(MysqLi_error($MysqLi));
$dates_id = MysqLi_fetch_assoc ( $result );
$comma_separated = implode(",",$dates_id);
echo $comma_separated; //This Returns 79,which is correct.
$sql = "SELECT SIteID FROM bookings WHERE BSH_ID = '1' AND MarketID = '$comma_separated'";
$result = MysqLi_query($MysqLi,$sql) or die(MysqLi_error($MysqLi));
// This is where my problems start
$SIteID = array();
while ($newArray = MysqLi_fetch_array($result,MysqLI_ASSOC)) {
$SIteID[] = $newArray[SIteID];
}
$locationList = implode(",$SIteID);
?>
最佳答案
如果这是您的意思,我会感到惊讶:
原文链接:https://www.f2er.com/mysql/532072.html... AND MarketID = '$comma_separated'
这就是说MarketID作为逗号分隔列表存储在数据库中.可能您的意思是:
... AND MarketID IN ($comma_separated)
另外,您不需要进行多个查询,可以使用JOIN:
SELECT SIteID
FROM marketdates
JOIN bookings
ON marketdates.MarketID = bookings.MarketID
WHERE bookings.BSH_ID = '1'
AND marketdates.Date = '2010-04-04 00:00:00'
AND marketdates.VenueID = '2'