1
$query = mysql_query("SELECT U.username, U.uid, U.full_name, M.uid_fk FROM tb_favorite M, tb_user U WHERE U.uid = M.uid_fk AND M.msg_id_fk = '$get_post_id' LIMIT 3");

while($row = mysql_fetch_array($query))
{
    $like_uid = $row['uid_fk'];
    $likeusername = $row['username'];
    $likefull_name = $row['full_name'];

if($like_uid == $uid)
{
    echo '<span id="youlikes'.$get_post_id.'">You</span>';
}
else
{
    echo '<span id="youlike'.$get_post_id.'"></span> <a href="'.$likeusername.'">'.$likefull_name.' </a>';
}
}
favorited this

Assuming I login using user1 (User1 is You). When the query running, it will show like this :

You, user2, User3 favorited this.

But if I login using user2, when query running, it will show like this :

User1, You, User3 favorited this.

I think it's because the first saved to table will show first.

What I want is, when I log on using User1/User2/User3, "You" must be first of another user when favorited this.

halfer
  • 19,824
  • 17
  • 99
  • 186
HiDayurie Dave
  • 1,791
  • 2
  • 17
  • 45

1 Answers1

1

You can use order by,

SELECT U.username, U.uid, U.full_name, M.uid_fk FROM tb_favorite M, tb_user U
WHERE U.uid = M.uid_fk AND M.msg_id_fk = '$get_post_id'
ORDER BY U.uid = $uid DESC
LIMIT 3

Warning: Please, don't use mysql_* functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial.

Zoe
  • 27,060
  • 21
  • 118
  • 148
Rikesh
  • 26,156
  • 14
  • 79
  • 87