Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.