Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

configure php page as a sort by column page

Status
Not open for further replies.

sap1958

Technical User
Oct 22, 2009
138
US
Here is some partial code from a php page I have

$display_block .= "
<table cellpadding = 0 cellspacing = 0 border=1 width=125%>
<tr><th>Last</th><th>First</th>

$last=mysql_result($result,$i,"last");
$first=mysql_result($result,$i,"first");

$i++;
$display_block .= "<tr>
<td align=left>$last<br></td>
<td align=left>$first<br></td>

How can I configure this so the user can select say the column last and sort(right on the page) descending or ascending on the fly, same for first and a few other columns like date_of_birth
 
You'd need to setup the column header as a link, and then dynamically construct the query based on the passed values so that the returned results are ordered how you want them.


For instance:
Code:
$orderby=mysql_escape_string($_GET['orderby];
$qry="SELECT *FROM mytable ORDER BY $orderby";
$res=mysql_query($qry);



<tr><th><a href="pagename.php?orderby=last"> Last</a></th><th><a href="pagename.php?orderby=first">First</a></th>


[/code]

this is is just a simple example, you'll need to d much more coding to get the order and the column name to order by and construct your query with them.



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top