我将尽可能简单地解释这一点。任何帮助将不胜感激,因为我不擅长设计查询。尝试解决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