Jump to content


Photo

Sort By


  • Please log in to reply
1 reply to this topic

#1 LiLaaron

LiLaaron
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 16 May 2006 - 08:24 AM

Hi,

Just wondering if someone could help me with this, i want to add 2 options.

Sort Username by ascending or descending in alphabetical order, So if its ascending it would show A's First or descending it would should Z's First.

Sort Points by ascending or descending in numerical order, So if its ascending it would show points with 0 First or descending it would should points XXXX First.

I would like the options to be a selection box, with no submit button, so it would be onChange="document.formid.submit() in the select tag.

Heres my code so far,


<BR>

<font color='FFFFFF' size='-1' face='Tahoma'><strong>List Users</strong></font><BR>
<font color='FFFFFF' size='-2' face='Tahoma'><strong>All Current Users Registered</strong></font><BR>
<hr color="#FFFFFF" align="left" width="80%">

<table width="50%" border="0">
  <tr>
    <td>

<?

$sql ="SELECT * FROM bb_users";

$result = @mysql_query($sql,$connection) or die(mysql_error());

while ($sql = mysql_fetch_object($result)) 

{

    $points = $sql -> user_points;
    $username = $sql -> username;
    $email = $sql -> user_email;

    ?>

<table width="100%" border="0">
  <tr>
    <td width="50%" align="right"><font color='FFFFFF' size='-1' face='Tahoma'><strong>Username: </strong></font></td>
    <td width="50%" align="left"><font color='FFFFFF' size='-1' face='Tahoma'><strong><? echo $username; ?></strong></font></td>
    </tr><tr>
    <td width="50%" align="right"><font color='FFFFFF' size='-1' face='Tahoma'><strong>Email Address: </strong></font></td>
    <td width="50%" align="left"><font color='FFFFFF' size='-1' face='Tahoma'><strong><? echo $email; ?></strong></font></td>
    </tr><tr>
    <td width="50%" align="right"><font color='FFFFFF' size='-1' face='Tahoma'><strong>Points: </strong></font></td>
    <td width="50%" align="left"><font color='FFFFFF' size='-1' face='Tahoma'><strong><? echo $points; ?></strong></font></td>
  </tr>
</table>
<br>

    <?
}

?>

    </td>
  </tr>
</table>

Thanks for any help
Aaron

#2 Kris

Kris
  • Staff Alumni
  • Advanced Member
  • 2,755 posts
  • LocationThe Internet

Posted 16 May 2006 - 09:16 AM

I haven't read through your code, but this is how you do it, shouldn't be too hard to understand and integrate into your code:
<?php
$orderby = (isset($_GET['orderby'])) ? $_GET['orderby'] : "name";
$ascdesc = (isset($_GET['ascdesc'])) ? $_GET['ascdesc'] : "ASC";

$result = mysql_query("SELECT * FROM `table` ORDER BY $orderby $ascdesc") or die(mysql_error());
//Loop through results etc...

echo "<a href='?orderby=age&amp;ascdesc=DESC'>ORDER BY DESCENDING AGE</a>";
echo "<a href='?orderby=name&amp;ascdesc=DESC'>ORDER BY DESCENDING NAME</a>";
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users