我有一个mysql查询,如下所示 -
$id_order_last="15";
$id_order[]=array();
$sql1="SELECT * FROM `ps_orders` WHERE `id_order`>
$id_order_last order by `id_order`";
echo $sql1;
$result1= mysql_query($sql1);
$cnt=1;
while ($row = mysql_fetch_array($result1))
{
/*$id_order[$i]=$row['$id_order'];*/
echo $row['$id_order']."<br />";
$cnt++;
echo $cnt."<br />";
}
正如您所看到的,我将$id_order_last
设置为15,因此在回显时将值显示为15。要检查sql我回显它并显示
SELECT * FROM `ps_orders` WHERE `id_order`> 15 order by `id_order`
所以我进入sql,在phpmyadmin中运行,获得返回的元组是正确的值。它显示了良好的结果意味着数据库中的17和18。这意味着查询是正确的!
然后它回显了2和3 cnt ++值,而$row['$id_order']
仍为空,只有<br />
显示为空格。
我还试过for循环来打印所有东西,但它仍然没有出现?
$i=1;
for($i;$i<=$cnt;$i++)
{
echo $id_order_last."<br />";
echo $id_order[$i]."<br />";
$id_order_last=$id_order[$i];
}
答案 0 :(得分:1)
use echo $row['id_order'] in place of echo $row['$id_order']
remove $.
答案 1 :(得分:1)
将$row['$id_order']
替换为$row['id_order']
$id_order_last="15";
$sql1="SELECT * FROM `ps_orders` WHERE `id_order`>
$id_order_last order by `id_order`";
echo $sql1;
$result1= mysql_query($sql1);
$cnt=1;
while ($row = mysql_fetch_array($result1))
{
$id_order[]=$row['id_order'];
echo $row['id_order']."<br />";
$cnt++;
echo $cnt."<br />";
}
echo "<pre />";
print_r($id_order);