Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
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');

?>
Reply With Quote
  #2 (permalink)  
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>";
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:32 AM.


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