我有这个查询
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)
答案 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"