我尝试运行两个查询以获取一个用户信息,以便在另一个上获取查询。它可以很好地获取正确的数据,但不允许我按日期排序,因为它不是父查询$ result所以我猜测我需要某种类型的JOIN或UNION用户,朋友和评论或者也许完全不同的东西。
我明白为了加入,必须有类似的列。请包括所有适当的引号,括号......等。
$result = mysqli_query($conn, "SELECT *
FROM users, friends
WHERE (users.id = friends.friend2)
") or die(mysql_error());
while($row = $result->fetch_assoc())
{
$friend1 = $row['friend1'];
$friend2 = $row['friend2'];
foreach(array($friend1) as $items) {
$my_comments = mysqli_query($conn, "SELECT *
FROM users, comments
WHERE ('$items' = comments.id_user)
AND ('$items' = users.id)
ORDER BY date DESC // this is where I'm stuck. It outputs data in ASC order.
") or die(mysql_error());
while($row = $my_comments->fetch_assoc())
{
$result = mysqli_query($con, "SELECT * FROM
( Select * FROM users as T1
JOIN friends as T2
ON T1.id = T2.friend2
WHERE (T1.id = T2.friend2)
AND 'something else'
AND 'something else' as T12
JOIN my_comments as T3
ON T12.friend1 = T3.id_user
WHERE (T12.friend1 = T3.id_user)
ORDER BY date DESC
") or die(mysql_error());
while($row = $my_comments->fetch_assoc())
{