Sep 04

I saw this method used in an old c cook book. Can’t remeber what it’s called, cascading switch anyone??


switch($section)
 {
 case 'year':
 if(empty($select))
 $select = ' * ';
 if(!empty($year))
 $where .= "    AND        `Year Range`    LIKE '%$year%' ";

 case 'submodel':
 if(empty($select))
 $select = ' TRIM(`Year Range`)';
 if(!empty($submodel))
 $where .= "    AND        `Model ID`         LIKE '%$submodel%' ";

 case 'engine':
 if(empty($select))
 $select = ' TRIM(`Model ID`) ';
 if(!empty($engine))
 $where .= "    AND        `Engine Size`     LIKE '%$engine%' ";

 case 'model':
 if(empty($select))
 $select = ' TRIM(`Engine Size`) ';
 if(!empty($model))
 $where .= "    AND     `Model Name`    LIKE '%$model%' ";

 case 'make':
 if(empty($select))
 $select = ' TRIM(`Model Name`) ';
 if(!empty($make))
 $where .= "    AND     `Make`             LIKE '%$make%' ";
 }

2 Responses to “Elegant way to construct SQL statements”

  1. star config web design sydney Says:

    thank you for article about SQL statment, it is really great example, especially i liked that you showed us everything all your steps, well done guys

  2. Pebbles Says:

    Slam dunkin like Shaquille O’Neal, if he wrote infoartmive articles.

Leave a Reply