正如您在此处所见,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 |
+-----------+
答案 0 :(得分:0)
没关系,谢谢。我通过分离查询解决了它。我只需要数量,否则无所谓。
$result = mysql_query("
SELECT COUNT(iid) AS total_photo
FROM images WHERE pid = '$pid'");