我將盡可能簡單地解釋這一點。任何幫助將不勝感激,因爲我不擅長設計查詢。嘗試解決MySQL查詢邏輯問題的新手
我有3個表:(我已削減了不必要的列在用戶表這個問題)
USERS:
id, username, password
PENDINGREVIEW:
id, articleid, requestid, content, writerid, datewritten
ARTICLES:
id, title, length, requestedby, content, writtenby, daterequested, datecompleted
所以說我有review.php
。在review.php
我希望它顯示特定用戶的pendingreview
表中的所有文章。因此,像這樣:
SELECT * FROM pendingreview WHERE requestid = $userid (where $userid = the id of the user)
什麼其實我是想顯示在review.php
雖然是從articles
表的文章,多少文章都在pendingreview
表對應於每個這些文章的列表。該列表只能由用戶請求的文章組成。
所以我想review.php
看起來像這樣:
Your "How to build a bike" article request has 3 articles pending review.
Your "How to mow the lawn" article request has 12 articles pending review.
上我會怎麼做任何幫助,將不勝感激!
我沒有任何問號。請先嚐試一下。並閱讀[faq] – 2013-03-19 08:04:01
我將使用什麼查詢?我不知道從哪裏開始! – KriiV 2013-03-19 08:07:16
@KriiV你的'SELECT ...'的例子正朝着一個好的方向前進。你需要'JOIN'你的表:[mysql-manual](http://dev.mysql.com/doc/refman/5.1/en/join.html),並在你的文章的ID上使用'count' ... – michi 2013-03-19 08:12:20