Home arrow PHP arrow Page 2 - Ordering Columns in DDBB Search Results

The Test Scenario - PHP

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

First, we'll create a products table in our MySQL test database and insert some records on it:

CREATE TABLE products (

  ID smallint(5) unsigned NOT NULL auto_increment,

  NAME varchar(125) NOT NULL default '',

  PRICE float(8,2) NOT NULL default '0.00',

  CODE varchar(10) NOT NULL default '',

  WEIGHT smallint(5) unsigned NOT NULL default '0',

  PRIMARY KEY (ID)

  ) TYPE=MyISAM;


INSERT INTO products VALUES (1, 'Absolute Delight', '2.20', '59', 50);

  INSERT INTO products VALUES (2, 'Aqua Mirabilis', '2.35', '114', 15);

  INSERT INTO products VALUES (3, 'Back For Breakfast', '8.30', '1409', 500);

  INSERT INTO products VALUES (4, 'Breeze on a Sea Air', '5.95', '223', 75);

  INSERT INTO products VALUES (5, 'Figs and Leaves', '3.90', '22819', 100);

  INSERT INTO products VALUES (6, 'I love Juicy', '5.95', '2006', 250);

  INSERT INTO products VALUES (7, 'Ocean Salt', '9.75', '2128', 150);

  INSERT INTO products VALUES (8, 'Serenity', '49.95', '2083', 350);

  INSERT INTO products VALUES (9, 'Tisty Tosty', '2.35', '5', 60);

  INSERT INTO products VALUES (10, 'Waving Not Drowning', '1.95', '15', 40);

If nothing went wrong we should have our products table with 10 records. We are now ready to jump into the actual code!



 
 
>>> 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: