Home arrow PHP arrow Ordering Columns in DDBB Search Results

Ordering Columns in DDBB Search Results

This article will show you the fastest way to order your database results, via JavaScript (with some work in PHP). It adds some more work to your script, but once you see the results you won't use the approach of adding the ORDER By clause anymore.

TABLE OF CONTENTS:
  1. Ordering Columns in DDBB Search Results
  2. The Test Scenario
  3. The Basic Code
  4. We Love InnerHTML!
  5. I Need More!
  6. The Final Words
By: Alvaro Calleja
Rating: starstarstarstarstar / 13
December 06, 2004

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement

Introduction

I bet most of us have at some point developed an application where a list of products is retrieved from a database and shown in a table with its name, price and code. Perhaps some of us thought: "Hey, let's be nice and give the user the chance to order these results by name or price." So we placed a cute little icon near each column's header that linked to the search page with a flag in the URL to let it know we wanted the results ordered by name or price. The search script kindly did its job, adding the ORDER BY clause, and the ordered results were shown to the user.

Obviously this works, but there is a problem: you must search again in your database, and send the user the whole page with the new results.

So let's think -- the first time you load the page, the results are already in the user browser. Why must we bother the server again to retrieve the same results in a different order?

This article will show you the fastest way to order your database results, via JavaScript (with some work in PHP). It adds some more work to your script, but once you see the results you won't use the approach mentioned above anymore.



 
 
>>> More PHP Articles          >>> More By Alvaro Calleja
 

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: