White_Lily Posted November 2, 2012 Share Posted November 2, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/270207-searching-for-exact-or-similar-messages/ Share on other sites More sharing options...
Christian F. Posted November 2, 2012 Share Posted November 2, 2012 Yep: $numsearch = mysql_num_rows($results); $getsearch = mysql_fetch_assoc($results); .... while($getfill = mysql_fetch_array($results)){ Quote Link to comment https://forums.phpfreaks.com/topic/270207-searching-for-exact-or-similar-messages/#findComment-1389678 Share on other sites More sharing options...
Pikachu2000 Posted November 2, 2012 Share Posted November 2, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/270207-searching-for-exact-or-similar-messages/#findComment-1389704 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.