liamoco Posted September 30, 2010 Share Posted September 30, 2010 I want to list all users by name but also by status for example Bob Charles - Online Bob Jones - Online Bob Back - Away but my names and status are in two different tables I order my names using ORDER BY fname, lname ASC // table name = users I order my status using ORDER BY FIELD(status, 'online', 'away', 'busy') //table name = user_info How can I do this? Thanks Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/ Share on other sites More sharing options...
liamoco Posted October 1, 2010 Author Share Posted October 1, 2010 How can I do this without putting the data into the same table? Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/#findComment-1117928 Share on other sites More sharing options...
fenway Posted October 2, 2010 Share Posted October 2, 2010 You mean a JOIN? Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/#findComment-1118374 Share on other sites More sharing options...
liamoco Posted October 3, 2010 Author Share Posted October 3, 2010 yes, this is what I have tried, not quite working, cannot get the join working, the field name status is from a different table called user_assign $query_online = mysql_query("SELECT id, fname, mname, lname FROM users JOIN chat_assign ON status WHERE id in ('" . implode("', '", $friend_id_array) . "') ORDER BY status, fname, lname"); Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/#findComment-1118446 Share on other sites More sharing options...
liamoco Posted October 3, 2010 Author Share Posted October 3, 2010 Sorry I forgot to post the error that is shown when using the query above. Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in J:......................\functions.php on line 164 Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/#findComment-1118529 Share on other sites More sharing options...
liamoco Posted October 3, 2010 Author Share Posted October 3, 2010 solved with this... $query_online = mysql_query("SELECT users.fname, users.mname, users.lname, chat_assign.status FROM users, chat_assign WHERE (users.id = chat_assign.user_id) AND users.id in ('" . implode("', '", $friend_id_array) . "') ORDER BY FIELD(chat_assign.status, 'online', 'busy', 'away'), users.fname, users.lname "); Link to comment https://forums.phpfreaks.com/topic/214865-order-by-using-two-different-tables/#findComment-1118535 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.