SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    Dec 2000
    Location
    Norcross, GA
    Posts
    136
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    	if ($sort == "date") {$order = "sortdate, pmsname, techid";}
    	if ($sort == "vendor") {$order = "pmsname, sortdate, techid";}
    	if ($sort == "techid") {$order = "techid, pmsname, sortdate";}
    	if ($sort == "lengthcall") {$order = "lengthcall, pmsname, techid";}
    	if ($sort == "fnum") {$order = "fnum, sortdate, techid";}
    	
    	$result = mysql_query("SELECT *, DATE_FORMAT(date,'$datesort') as sortdate, DATE_FORMAT(date,'$dateformat') as date, DATE_FORMAT(lengthcall,'$timeformat') as lengthcall FROM outdated,pms,ver WHERE outdated.verid=ver.verid AND pms.pmsid=ver.pmsid ORDER BY '$order'",$db);
    Any clue why this routine returns the same order of records no matter what sort variable is given?

    Thanks!

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try removing the single quotes from around the $order
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would also suggestion using a SWITCH statement in place of the IF conditionals. My general rule of thumb is that, when declaring the value of a variable that way, anymore than 2 possible outcomes should be handled with a SWITCH statment.

    It should go a little something like this:

    PHP Code:
    switch ($sort) {
      case 
    "date"
        
    $order "sortdate, pmsname, techid";
        break;
      case 
    "vendor"
        
    $order "pmsname, sortdate, techid";
        break;
      case 
    "techid"
        
    $order "techid, pmsname, sortdate";
        break;
      case 
    "lengthcall"
        
    $order "lengthcall, pmsname, techid";
        break;
      case 
    "fnum"
        
    $order "fnum, sortdate, techid";
        break;

    You should be able to replace your if statements with that block of code...good luck!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •