查询在phpmyadmin中有效,但在页面上没有显示id

时间:2016-12-06 05:49:27

标签: php mysql phpmyadmin

我有这个查询

SELECT a.*, b.*, c.*, e.*, d.* 
FROM categories a 
JOIN categories b ON(a.categoryID=b.parentCategory) 
JOIN products c ON(b.categoryID=c.categoryID) 
LEFT JOIN productprice d ON (d.productID = c.productID) 
JOIN currency e ON (e.currencyID = 1)   
WHERE a.categoryID in (263,264,265,266,267,268,306,256,0) 
ORDER BY a.priority 

当我直接在phpmyadmin中运行查询时,我得到了正确的结果,一切都在那里。

问题是我在页面上运行它然后尝试显示productID我已经NULL。这就是我在网页上尝试的内容

$query = "SELECT a.*, b.*, c.*, e.*, d.* 
FROM categories a 
JOIN categories b ON(a.categoryID=b.parentCategory) 
JOIN products c ON(b.categoryID=c.categoryID) 
LEFT JOIN productprice d ON (d.productID = c.productID) 
JOIN currency e ON (e.currencyID = 1)   
WHERE a.categoryID in (263,264,265,266,267,268,306,256,0) 
ORDER BY a.priority";

$result= mysql_query($query);
while($row=mysql_fetch_object($result) {

      var_dump($row->productID);
}

所有$ row-> productID均为NULL

更新:var_dump($result);返回

resource(286) of type (mysql result)

1 个答案:

答案 0 :(得分:1)

Please try with this query

$query = "SELECT a.*, b.*, c.*, e.*, d.* ,c.productID as productID
FROM categories a 
JOIN categories b ON(a.categoryID=b.parentCategory) 
JOIN products c ON(b.categoryID=c.categoryID) 
LEFT JOIN productprice d ON (d.productID = c.productID) 
JOIN currency e ON (e.currencyID = 1)   
WHERE a.categoryID in (263,264,265,266,267,268,306,256,0) 
ORDER BY a.priority"