Log in

View Full Version : Organise by user defined method



ragdoll2309
03-28-2013, 12:30 AM
Below is the code I have used to output a table (with headers). This is working fine (obviously I have removed the call to the database as this isn't necessary to show)

I was hoping somebody could help me, I want this to be able to be ordered by any of the headers and with a simple method of doing so (ideally clicking on the header, but don't know if this is possible or by a dropdown menu on the same page)

I'm relatively new to php (having come from mainly ASP & ASP.NET background).
Please ignore my sloppy code but it worked for what I needed it for first day!

Thanks for any help you can give me!





$result = mysql_query("SELECT * from student");

//Table starting tag and header cells
echo "<table border='1'><tr><th>ID</th><th>Name</th><th>Surname</th><th>Gender</th><th>Date Of Birth</th><th>Telephone</th><th>Request</th><th>Agent</th><th>Host Family ID</th><th>Airport Name</th><th>Airport Arrival Date</th><th>Airport Arrival Time</th><th>Added Details</th></tr>";
while($row = mysql_fetch_array($result))
{
//Display the results in different cells
echo "<tr><td>" . $row['sid'] . "</td><td>" . $row['sname'] . "</td><td>" . $row['ssurname'] . "</td><td>" . $row['sgender'] . "</td><td>" . $row['sdob'] . "</td><td>" . $row['stelephone'] . "</td><td>" . $row['srequest'] . "</td><td>" . $row['sagent'] . "</td><td>" . $row['shostfamilyid'] . "</td><td>" . $row['safairport'] . "</td><td>" . $row['safdate'] . "</td><td>" . $row['saftime'] . "</td><td>" . $row['details'] . "</td></tr>";
}
//Table closing tag
echo "</table>";

Beverleyh
03-28-2013, 06:25 AM
Maybe a JavaScript solution would suit your needs. I've used this jQuery tablesorter plugin in a few projects: http://tablesorter.com/docs/ otherwise there's plenty of choice here: http://www.tripwiremagazine.com/2012/05/jquery-filter-sort-plugins.html

ragdoll2309
03-28-2013, 10:21 AM
Maybe a JavaScript solution would suit your needs. I've used this jQuery tablesorter plugin in a few projects: http://tablesorter.com/docs/ otherwise there's plenty of choice here: http://www.tripwiremagazine.com/2012/05/jquery-filter-sort-plugins.html

Thanks Beverley, I'll definitely try these out. I tried the tablesorter quickly but it may be my stupid brain or something else but it's not working for me. I'm sure one of what you showed me will work! Appreciate it!