1

正如您在此处看到的,TotalPic列 return 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  |
+-----------+
4

1 回答 1

0

没关系,谢谢。我通过分离查询来解决它。我只需要计数,其他无关紧要。

$result = mysql_query("
          SELECT COUNT(iid) AS total_photo 
          FROM images WHERE pid = '$pid'");
于 2012-08-07T04:10:49.810 回答