如您所见,TotalPic
列返回 0
。有什么问题?
SELECT P.*, U.*, COUNT(I.iid) AS TotalPic
FROM post P
LEFT JOIN users U ON U.uid = P.uid
LEFT JOIN images I ON I.pid = P.uid
WHERE P.pid = '2'
我尝试像这个线程解决方案一样使用 LEFT JOIN
MYSQL COUNT return NULL? , 但还是一样。
+-----------+
| images |
+-----------+
| iid |
| filename |
| extension |
| pid |
| uid |
+-----------+
+-----------+
| post |
+-----------+
| pid |
| uid |
|description|
| created_at|
+-----------+
+-----------+
| users |
+-----------+
| uid |
| fid |
| date_reg |
+-----------+
最佳答案
没关系,谢谢。我通过分离查询解决了它。我只需要计数,其他都无关紧要。
$result = mysql_query("
SELECT COUNT(iid) AS total_photo
FROM images WHERE pid = '$pid'");
关于MySQL 计数返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11680381/