LiLaaron Posted May 16, 2006 Share Posted May 16, 2006 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 helpAaron Quote Link to comment Share on other sites More sharing options...
zq29 Posted May 16, 2006 Share Posted May 16, 2006 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&ascdesc=DESC'>ORDER BY DESCENDING AGE</a>";echo "<a href='?orderby=name&ascdesc=DESC'>ORDER BY DESCENDING NAME</a>";?>[/code] Quote Link to comment 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.