Jump to content

[SOLVED] How do i sort a mysql_fetch_array


Wildhalf

Recommended Posts

Hi 

 

I need some help. The While loop below returns and displays exactly what i want but i want to sort the rows by $row['no_referrals'] showing the largest first. Has anyone any ideas how i do this???

 

$sql = mysql_query("SELECT * FROM tblmembers WHERE referred_by='$member_id'") or
die(mysql_error());
  
//$num_rows = mysql_num_rows($sql_num_rows);

//now you could do something like this to make sure that you don't loop 
//through the results if there aren't any to be looped through
if (mysql_num_rows($sql) < 1) {
    die("There are not matching results");
}  
  
//now we loop through the results..
//for ( $counter = 0; $counter <= $num_rows ; $counter += 1) {
while($row = mysql_fetch_array($sql)) {

echo '<tr bgcolor="#FFFFCC">
		<td  align="center" width="160" height="20" bgcolor="#eeeeee">
			<div align="center" class="style5">';	
echo $row['firstname'];
echo ' ' ;
echo $row['lastname']; 
echo '<div>
		</td>
			<td width="160" height="20" bgcolor="#eeeeee">
				<div align="center" class="style5"> ';
echo $row['no_referrals'];
echo '</div>
		</td>
			<td width="160" height="20" bgcolor="#FFFFCC" scope="row">
				<div align="center" class="style5"> ';
echo '<a href="mailto:';
echo $row['email'];
echo '">';
echo $row['email'];
echo '</a>';
echo '</div>
		</td>
				</tr> ';

}

Link to comment
Share on other sites

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.