Wrox Programmer Forums
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 14th, 2009, 05:16 PM
Registered User
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default sort tables

how do i sort a table by clicking on the header link?

I tried doing this but it involves too many files (one for each sortable columns).
what are the other (better) ways to do this?

also how to alternate the order (ascending/desending) with every click


thanks

Code:
page1.php

if(isset($_SESSION['test5']))
{
	$result = mysql_query($_SESSION['test']);
}
else
{
	$result = mysql_query("SELECT * FROM student");		//default
}
	
	echo "<table>";  
	echo "<tr class='header'>"; 
	
	echo "<td>";  
	echo "<a href='testing.php'>ID</a>";  
	echo "</td>";  

	echo "<td>";  
	echo "<a href='testing2.php'>NAME</a>"; 
	echo "</td>";  
	
	echo "</tr>"; 	


	echo "<tr>"; 
	echo "<td>" . $row['id'] . "</td>";
	echo "<td>" . $row['name'] . "</td>";
	echo "</tr>"; 

	echo "</table>";
Code:
testing.php
<?php session_start();

$_SESSION['test5'] = "SELECT * FROM STUDENT ORDER BY id";

header('LOCATION: page1.php');

?>
Code:
testing2.php
<?php session_start();

$_SESSION['test5'] = "SELECT * FROM STUDENT ORDER BY name";

header('LOCATION: page1.php');

?>
 
Old October 17th, 2009, 09:54 PM
Registered User
 
Join Date: Oct 2009
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

ignore my post above. figured this out already

i didn't know you could do this:



Code:
page1.php

echo "<a href='testing.php?sortby=id'>ID</a>";  
echo "<a href='inc.sortstudent.php?sortby=name_last'>NAME</a>";





Similar Threads
Thread Thread Starter Forum Replies Last Post
Interactive sort in hidden tables golliaph Reporting Services 0 August 18th, 2008 06:21 AM
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
creating tables within tables in access??? carswelljr Access 3 August 23rd, 2006 01:21 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
Unable to sort using xsl sort command sly_jimmy_boy XSLT 3 June 17th, 2005 05:15 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.