affordit Posted July 4, 2013 Share Posted July 4, 2013 I am trying to pull results from a messages table and group the messages by a thread_id I have 3 messages with the same thread_id, but when I get the results it comes out like this; SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 1 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 2 SUBJECT 1 - MESSAGE 3 SUBJECT 1 - MESSAGE 3 SUBJECT 1 - MESSAGE 3 SUBJECT 2 - MESSAGE 1 can someone tell me where I screwed up? Here is what I have, function getMessages($user_id){ $user_id = $_SESSION['user_id']; $query = mysql_query("SELECT * FROM `messages` WHERE `recipient_id` = $user_id or `sender_id` = $user_id"); while ($row = mysql_fetch_array($query)){ $thread_id = $row['thread_id']; $result = mysql_query("SELECT COUNT(message_id) FROM `messages` WHERE `thread_id` = $thread_id"); $count = mysql_result($result,0); $i = 0; while($i != $count){ $message_id = $row['message_id']; $subject = $row['subject']; $message = $row['message']; $sender_id = $row['sender_id']; print "<p style = 'padding-left:10px; font-weight:bold;'>$message</p>"; $i++; } print "<p style = 'padding-left:10px; font-weight:bold;'><hr></p>"; } } $m = getMessages($user_id); print $m; Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/279877-can-someone-explain-why-this-does-not-work/ Share on other sites More sharing options...
Solution affordit Posted July 5, 2013 Author Solution Share Posted July 5, 2013 (edited) I think I got it thanks Edited July 5, 2013 by affordit Quote Link to comment https://forums.phpfreaks.com/topic/279877-can-someone-explain-why-this-does-not-work/#findComment-1439488 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.