私のSQLテーブルは次のようなものです
posts-> id postedby timestamp
1 1 12716826
comments-> id postid comby tstamp condition
1 1 1 12716826 me
2 1 1 12716826 all
1 1 2 12716826 me
1 1 3 12716826 all
私の質問は、投稿 1 のすべてのコメントを取得するクエリを作成するときです。次の条件が欲しい
私という条件付きのコメントは、私または投稿所有者のみに表示される必要があります
$myid=2; のようなクエリを作成しました。$postbyid=1;
$res=$db->query("SELECT * from comments where postid='$postbyid'
order by tstamp desc");
while ($row=$res->fetch_assoc())
{
if($row['comby']==$uid || $row['comby']=='$postbyid')
{
$data[]=$row;
}
else
{
if($row['condition']!='me')
{
$data[]=$row;
}
}
}
これは間違っているかもしれません。を使用してこれを行う方法はありSQL CASE
ますか?
お気に入り
SELECT * from comments where postid='$postbyid' CASE WHEN comby='$myid'
THEN SHOW ALL WHEN combyid='$postbyid' THEN SHOW ALL else dont
show this row order by tstamp desc