Jump to content

Searching For Exact Or Similar Messages


White_Lily

Recommended Posts

Hi, i have an inbox system where by people can create and send messages to different, the user can see the list of messages that they have and they can also search for specific messages from certain users.

 

i have written this:

 

<?php

$results = select("*", "users, messages", "users.username = messages.to AND messages.to = '$u' AND messages.from LIKE '%$searchquery%'") or die(mysql_error());
$numsearch = mysql_num_rows($results);
$getsearch = mysql_fetch_assoc($results);

echo '<p>Results Found: '.$numsearch.'</p>';
echo '<img src="'.$GLOBALS["nav"].'images/vertical-rule.png" />';
echo '<div class="clear" style="height:30px;"></div>';

echo '<table border="0">';
echo '<th width="1%">Senders Avatar</th>';
echo '<th width="25%">From</th>';
echo '<th width="25%">To</th>';
echo '<th width="25%">Options</th>';

if($numsearch > 0){
while($getfill = mysql_fetch_array($results)){
echo '<tr>';
echo '<td width="1%">';
if(empty($getfill["avatar"])){
echo '<img src="'.$GLOBALS["nav"].'images/avatar.png" />';
}elseif(!empty($getfill["avatar"])){
echo '<img src="'.$getfill["avatar"].'" />';
}
echo '</td>';
echo '<td width="25%"><p>'.$getfill["from"].'</p></td>';
echo '<td width="25%"><p>'.$getfill["to"].'</p></td>';
echo '<td width="25%">';
echo '<a href="#">View Message</a>';
echo '<a href="#">Delete Message</a>';
echo '</td>';
echo '</tr>';
}
}elseif($numsearch == 0){
echo '<tr>';
echo '<td colspan="4">';
echo "<p>There are currently no messages to view!</p>";
echo '</td>';
echo '</tr>';
}

echo '</table>';

?>

 

the problem that i am having is the $numsearch is returning "2", whereas the while loop is only displaying one message...

 

any ideas?

Link to comment
https://forums.phpfreaks.com/topic/270207-searching-for-exact-or-similar-messages/
Share on other sites

When you call mysql_fetch_assoc(), it advances the data pointer to the next result without doing anything with it. Then when you use mysql_fetch_assoc() in the while loop, the data pointer is set to the second - and in this case, last - result.

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.