Jump to content

Can someone explain why this does not work


affordit

Recommended Posts

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

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.