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
https://forums.phpfreaks.com/topic/36677-solved-how-do-i-sort-a-mysql_fetch_array/
Share on other sites

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.