phpnewbie25 Posted July 2, 2009 Share Posted July 2, 2009 Hi, I need help with customised sorting, below shows a table being populated by an SQL database. how would I be able to choose which row is sorting it? like if i clicked the top of one row it would sort it by that one? Thanks in advance <html> <head> <title>View Contacts</title> </head> <body> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <H1 ALIGN=center><IMG SRC="Images/logo.jpg" ALT="IOM Logo"></H1> <p align=center> <table table border='1' cellspacing=5 bgcolor=darkgray> <tr><td>ID</a></td><td>First Name</td><td>Last Name</td><td>Organisation</td><td>Address</td><td>Email</td><td>Phone</td><td>Fax</td></tr> <?php while($row=mysql_fetch_array($getUser)) { echo" <tr bgcolor=lightgray> <td>$row[id]</td> <td>$row[first_name]</td> <td>$row[last_name]</td> <td>$row[organisation]</td> <td>$row[address]</td> <td>$row[email]</td> <td>$row[phone]</td> <td>$row[fax]</td> </tr>"; } ?> </table> </p> Quote Link to comment https://forums.phpfreaks.com/topic/164580-customised-sorting/ Share on other sites More sharing options...
xtopolis Posted July 3, 2009 Share Posted July 3, 2009 Typically you make the <TH> clickable with the link being something like somepage.php?sortby=(nameofelement)&dir=asc Where (nameofelement) could be phone, first name, email... etc.. the names of your columns. The dir would be something that changes based on the previous state (toggle). You would then pick them up on the page and check the link before running the query. Is this a PHP or MySQL question? You posted not enough of either. Quote Link to comment https://forums.phpfreaks.com/topic/164580-customised-sorting/#findComment-868143 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.