my script doesn't sort on date.

Discussion in 'PHP' started by harlequeen, Jun 15, 2006.

  1. #1
    I recently followed a tutorial on making php divide output into pages and display previous 1 2 3 4 next etc on the pages. However, my select function does not now sort on the date as I have requested.

    $max_results=8;
    
    //Work out the limit for the query based on 
    //current page numer
    
    $from = (($page * $max_results) - $max_results);
    
    //Perform MySQL query on only the current page number's resluts
    // descending order of date, followed by limit of query
    $sql=mysql_query("SELECT DATE_FORMAT(gigs.date,'%W %e %M , %y ') as date, venue, town FROM gigs ORDER BY date desc LIMIT $from, $max_results");
    
    
    
    while(@$row=mysql_fetch_array($sql)){
    
    //Build formatted result here
    echo("<h4>");
    echo $row['date'] ;
    echo ("<br>");
    echo $row['venue'];
    echo (", ");
    echo $row['town']."<br/>";
    echo ("<p>");
    echo("</h4>");
    
    }
    PHP:
    This is the output I get:
    As you can see, it isn't sorting. I can't seem to get this right.

    Any help would be appreciated.

    cheers
    Harlequeen
     
    harlequeen, Jun 15, 2006 IP
  2. woodside

    woodside Peon

    Messages:
    182
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Is the "date" field in your database a date type or something else?
     
    woodside, Jun 15, 2006 IP
  3. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #3
    Replace the query by this
    
    #
    $sql=mysql_query("SELECT DATE_FORMAT(gigs.date,'%W %e %M , %y ') as date, venue, town FROM gigs ORDER BY gigs.date desc LIMIT $from, $max_results");
    #
    
    PHP:
     
    goldensea80, Jun 16, 2006 IP
  4. harlequeen

    harlequeen Peon

    Messages:
    13
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks Goldensea80, that's sorted it out.

    Thanks for your help, and you, Woodside.

    Cheers
    H
     
    harlequeen, Jun 16, 2006 IP
  5. sketch

    sketch Well-Known Member

    Messages:
    898
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    148
    #5
    I would rename your "date" field to something else... you never want fields or variables with names that might conflict with functions.
     
    sketch, Jun 16, 2006 IP