I am making a online social networking site, and have messging section, i want it to make it show only 1 messge from each user, So if you have a message from

for ex
Username "bob"
id "32"

and you have 5 messages from him

Then you have 20 messages from
username: heather
id: 63

then you have 12 messages from
username: tony
id: 21

You will only have 3 messages in your inbox 1 from each of these users. And each one displays 120 characters from the last message they sent.

How could i do this, then when they click on the message it will take them some where else to see there whole conversation?

this is the code i have for getting the information from the databse and echo it out.

$ID = $_COOKIE['idCookie'];
            $query = mysql_query("SELECT * FROM  `private_messages` WHERE to_id LIKE  '$ID' AND To_Deleted LIKE '0' ORDER BY id DESC"); 
            echo "<table width='100%' border='1'>";
            $num = mysql_num_rows($query);
            if ($num > 0){
            while($row = mysql_fetch_assoc($query)){
            $id = $row['id'];
            $subject = $row['subject'];
            $toid = $row['to_id'];
            $read = $row['opened'];
            $fromid = $row['from_id'];
            $message = $row['message'];
            $id = $row['id'];
            $check_pic = "members/$fromid/image01.jpg";
            $default_pic="members/0/default.png";
                if(file_exists($check_pic)){
                $user_pic ="<img src=\"$check_pic\" width=\"50\" heign='50'>";
                }else{
                    $user_pic ="<img src=\"$default_pic\" width=\"50\" heign='50'/>";
                    }
                    if ($toid==$myid){
                        $query2 = mysql_query("SELECT * FROM `members` WHERE id LIKE '$fromid'");
                        while ($row = mysql_fetch_assoc($query2)){
                        $firstname = $row['firstname'];
                        $lastname = $row['lastname'];
                        if ($read =='1'){
                        $read = "Read";
                        }else{
                        $read="<a href='messages.php?Read=$id'>Mark as read</a>";
                        }
                        echo "<tr><td width='52'>$user_pic</td><td>From: <a href='/profile.php?id=$fromid'>$firstname $lastname</a> &nbsp; - &nbsp; <a href='messages.php?removeid=$id'><font color='red'>Delete</font></a> &nbsp; - &nbsp; $read
                        </br><hr>$message</td></tr>";
            //}
            }
            }
            }
            }else{
            echo "Your inbox is empty.";
            }
            echo "</table>";

SELECT * FROM private_messages WHERE to_id LIKE '$ID' AND To_Deleted LIKE '0' ORDER BY id DESC limit 1

Almostob, that would only show 1 altoghether, i want to show one from each member, so say you have 20 friends messaging you, and say you have 2 messages from each member, instead of 40 messages showing in your inbox, you would only have 20 in your inbox.

Your queries are wrong - you should be using = NOT LIKE when selecting by matching id (or any other data). LIKE is for finding similar data.

With regard to selecting one message for each batch of messages:

$query = mysql_query("SELECT * FROM  `private_messages` WHERE to_id='$ID' AND To_Deleted=0 ORDER BY id DESC LIMIT 1");

Simplypixie, i do not wnat to limit the inbox to 1 post altogether, i want it to be kinda like facebook, where they show 1 message from each person who sent you a message, Then when you click on it it will show you your whole conversation....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.