Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.