kirkh34 Posted May 7, 2010 Share Posted May 7, 2010 i have two tables which hold message data for sent and received messages, im trying to display messages that have been put in the trash, how do i access two tables at once to display the message data, the code i have doesn't work of course but i have both queries with the tables i need the data from <?php $sql = mysql_query("SELECT * FROM message_rec WHERE to_user ='$id' AND message_trash = '1' ORDER BY message_date DESC") or die (mysql_error()); $sql = mysql_query("SELECT * FROM message_sent WHERE from_user ='$id' AND message_trash = '1' ORDER BY message_date DESC") or die (mysql_error()); while ($row = mysql_fetch_array($sql)) { $message_id = $row["message_id"]; $message_content = $row["message_content"]; $message_date = $row["message_date"]; $message_title = $row["message_title"]; $to_id = $row["to_user"]; $message_read = $row["message_read"]; Link to comment https://forums.phpfreaks.com/topic/200980-grabbing-data-from-multiple-tables/ Share on other sites More sharing options...
phpchamps Posted May 7, 2010 Share Posted May 7, 2010 why dont you use UNION and merge both query into one it will give you records from both the tables... For more information about UNION follow below link:- http://dev.mysql.com/doc/refman/5.0/en/union.html If UNION doesnt solve your problem then merge the result of both the queries by using array_merge() Link to comment https://forums.phpfreaks.com/topic/200980-grabbing-data-from-multiple-tables/#findComment-1054478 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.