Database Articles
  Home arrow Database Articles arrow Sorting Database Results with PHP
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Forums Sitemap 
Dedicated Servers  
Download TestComplete 
JMSL Numerical Library 
IBM® developerWorks
Weekly Newsletter 
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DATABASE ARTICLES

Sorting Database Results with PHP
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 5
    2002-09-24

    Table of Contents:
  • Sorting Database Results with PHP
  • The Code

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Sorting Database Results with PHP


    (Page 1 of 2 )

    This tutorial will show you how to display data from a database and allow the user to sort it.

    I've been asked many times to write a tutorial that explains how to display data from a database and gives the user an option to sort the data by different columns. So, here it is!

    The method of doing this is, in fact, very simple. When you display your data, just make each column heading clickable and have it pass the column name as a value. Then, when you make your query, use that value in the ORDER BY clause and display the data again.

    You will see in the script that I am about to present to you, that it is good practice to specify a default value for the ORDER BY in case nothing has been chosen yet. I also add some error checking to make sure that the value for the ORDER BY clause is an acceptable value and won't cause the query to fail. This is accomplished by placing all acceptable values in an array and checking the passed in value against that.

    The array that I just mentioned is also used to decide whether a particular column is a column we want sorted when we display the data.

    Anyway, I'll just let the script do the rest of the talking. It is commented fairly well and should be self explanatory. If you do have any questions, always feel free to ask them in the forums!

    More Database Articles Articles
    More By Matt Wade


       · Hi, I have got this code working about 99%. In the table I have a field called Key,...
       · Well this is very useful code though i found a bug in it.That is i guess on code...
     

    DATABASE ARTICLES ARTICLES

    - More on Query Optimization for Oracle Databa...
    - Query Optimization in Oracle
    - Clusters and Other Data Structures for Oracle
    - Using Indexes with an Oracle Database
    - The Basics of Data Structures in Oracle
    - Oracle Data Structures
    - Best Practices for PL/SQL Variables
    - What`s Code Without Variables?
    - Clauses, Sorting, and SQL Queries
    - The From Clause and SQL Queries
    - Query Primer
    - Full Text Searches and Strings
    - Searching with Strings
    - Pattern Matching with Strings
    - Working with Cases of Strings






    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway