Jump to content

Archived

This topic is now archived and is closed to further replies.

LiLaaron

Sort By

Recommended Posts

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,

[code]

<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>
[/code]

Thanks for any help
Aaron

Share this post


Link to post
Share on other sites
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:
[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>";
?>[/code]

Share this post


Link to post
Share on other sites

×

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.