我在使用此脚本时遇到问题,我将不胜感激:
<? php
//ini_set('display_errors', '1');
//MQSQL connection
require_once('../../include/init.phph');
function transportQueue(){
//siteinfoDbCon();
siteinfoDbConNoLag();
$query = "SELECT
a.transport_id, a.site_id, b.site_name, c.name as 'From DC',
d.name as 'To DC', a.cutover, a.working, a.error
FROM transport_queue a
INNER JOIN sites b ON(a.site_id=b.site_id)
INNER JOIN datacenters c ON(a.from_dc_id=c.datacenter_id)
INNER JOIN datacenters d ON(a.to_dc_id=d.datacenter_id)
WHERE
a.cutover BETWEEN NOW() AND ADDDATE(NOW(), INTERVAL 7 day)
ORDER BY a.cutover";
//Pull results
$results=mysql_query($query);
//Return into an array $transports
while($row=mysql_fetch_array($results,MYSQL_BOTH)){
$transports[]=$row;
print_r($transports[0]["site_id"]);
}
//Free up the results
mysql_free_result($results);
//Close the db connection
siteinfoDbClose();
}
transportQueue();
?>
我可以确认查询是否有效以及数据库连接是否有效......我很茫然。
我正在尝试将结果返回到关联数组中。我确实审核了以下问题/答案:Dump mysql_fetch_array results into a multidimensional array
尝试
有什么想法吗?
答案 0 :(得分:1)
这个
while($row=mysql_fetch_array($results,MYSQL_BOTH)){
$transports[]=$row;
print_r($transports[0]["site_id"]);
}
替换此
$transport = array();
while($row=mysql_fetch_assoc($results))
$transports[]=$row;
print_r($transports);
现在是时候转移到MySQLi http://www.php.net/manual/en/book.mysqli.php
了答案 1 :(得分:0)
这一行:
print_r($transports[0]["site_id"]);
...总是在第一行传输中查看单个值['siteid'],而不是数组。拉出来,然后在循环结束后运行:
print_r($transports);
......你应该得到你想要的结果。