Jump to content

How to limit this?


davidb52

Recommended Posts

hello,i want a short of message system like on your phone.you see a message by number and the last message.if you press on it you see every message sent/received.this is what i want:http://imageshack.us/photo/my-images/812/testdasd.png/(i clicked on it)so i see the sent/reveived and under it all reveived message.but i want to limit where name is the same, so only show the one with - and don't show the old message (x).because if you click on it (what i did) you see all the message.

<div id='textmessage'><?php // messageif($_SERVER['REQUEST_METHOD']=='GET' and isset($_GET['u'])){include("../security/dbconnect.php");$user = $_GET['u'];$query = mysql_query("SELECT id FROM users WHERE easyname='" . mysql_real_escape_string( $user ) . "'");$count = mysql_num_rows($query);if($count!=0){while($row1 = mysql_fetch_array($query)){$ido = $row1['id'];}include("../security/dbconnecta.php");$query = mysql_query("SELECT dbfrom,dbto,message,dbdate,dbread FROM dbtext WHERE dbfrom='" . mysql_real_escape_string( $ido ) . "' AND dbto='" . mysql_real_escape_string( $id ) . "' OR dbto='" . mysql_real_escape_string( $ido ) . "' AND dbfrom='" . mysql_real_escape_string( $id ) . "' ORDER BY dbdate DESC");while($row1 = mysql_fetch_array($query)){$from = $row1['dbfrom'];$message = $row1['message'];$date = $row1['dbdate'];?><span <?php if($from==$id){ echo 'style="float:right;color: red;"'; } ?>><span style="font-size:0.6em;"><?php echo substr($date, 5, 11); echo ':';?></span><?php echo $message;?></span><br /><?php }}else{die("");}}?></div><div id="text"><table><?phpinclude("../security/dbconnecta.php");$query = mysql_query("SELECT dbto FROM dbtext WHERE dbto='" . mysql_real_escape_string( $id ) . "'");$count = mysql_num_rows($query);   if($count!=0){   $query = mysql_query("SELECT dbfrom,message,dbdate,dbread FROM dbtext WHERE dbto='" . mysql_real_escape_string( $id ) . "' ORDER BY dbdate DESC");   while($row1 = mysql_fetch_array($query)){   $data[] = $row1;   foreach ($data as $row1);   $from = $row1['dbfrom'];   $message = $row1['message'];   $date = $row1['dbdate'];   $read = $row1['dbread'];   include("../security/dbconnect.php");   $query2 = mysql_query("SELECT easyname FROM users WHERE id='" . mysql_real_escape_string( $from ) . "'");   while($row2 = mysql_fetch_array($query2)){   $data[] = $row2;   foreach ($data as $row2);   $easynameo = $row2['easyname']; ?><tr><td><a href='profileothers.php?n=<?php echo $easynameo ?>'><?php if(strlen($easynameo)>9){echo substr($easynameo, 0, 9);} else{ echo $easynameo; } ?></a></td><td><?php if($read==0){ ?> <b> <?php } ?><a href='text.php?u=<?php echo $easynameo; ?>'><?php if(strlen($message)>18){echo substr($message, 0, 18); echo '...';} else{ echo $message; } ?></a></td><td><?php if(strlen($date)>10){ echo substr($date, 5, 11);} ?></td></tr><?php }}} ?></table></div>

i hope you understand.

Link to comment
Share on other sites

Yes, all you would need to do is run a query to get all the names of the senders/recipients.

$result = mysql_query("SELECT DISTINCT dbfrom FROM dbtext");while($arr = mysql_fetch_array($result)){$name = $arr[0];...}

Then you can set it so when you click on the name you go to a page where it just shows messages from that user. Or you could take each name and run another query that checks it by the name and orders by the most recent message. Then use LIMIT 0, 1 to only get the very most recent message and print it.

Link to comment
Share on other sites

It should unless you are seeing otherwise. Using DISTINCT in a query says that you don't want any repeats. So what you want to do is get each unique person and then do a second query for each found unique person. The second query would get that persons most recent message.Now that I think about it, since some people might have the same name you might instead want to run DISTINCT on the id instead of the name.

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...