3つの列questionid
がreplyid
ありuserid
ます。
すべてを選択したいのでquestionid's from userid where userid is session[userid]
、それとは別に選択しますquestionid
。
今、私は配列questionid
に属するすべてのものを取り$_SESSION['user_id']
(そしてそれから重複を削除し)、それから私は再び別のクエリを渡します
foreach($array as $x)
{
$query="select questionid,replyid,userid from table where questionid=$x"
}
しかし、上記の手順はクエリ自体で実行できると思います(上記の手順も機能していません)。以下を試しましたが、機能しません。このクエリを渡そうとすると、重複する値が発生します。
SELECT distinct(questionid),replyid,userid
from table
where userid=$_SESSION['user_id']
では、クエリはどうあるべきですか?
questionid,replyid,userid
8 ,2 ,45
8 ,3 ,45
9 ,8 ,41
しかし、 8,2
と8,3
は同じWebページ(1つの質問と2つの回答)にあるので、重複する質問を表示しないようにします...
それで、私ははっきりquestionid
と取っていたので間違った方法を試みていました、そしてそれから再び選択* from table where questionid
は前のものでした。
しかし、@ Mahmoud Gamalが提案したように、私は
SELECT distinct questionid, `answerid`, `userid`
FROM `table`
WHERE userid='$user'
しかし、再び私は同じ重複したことをしました。だから私は追加しましたlimit 0,1
SELECT distinct questionid, `answerid`, `userid`
FROM `table`
WHERE userid='$user'
LIMIT 0,1