Jump to content

Customised Sorting


phpnewbie25

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/164580-customised-sorting/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/164580-customised-sorting/#findComment-868143
Share on other sites

Archived

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

×
×
  • Create New...

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.