SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Sort a query

  1. #1
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I wrote a news script in php togheter with mySQL.

    This is the script to display the results, this works fine:
    PHP Code:
    <?
    require("config.php");
    ?>
    <style>
    <?=$style;?>
    </style>
    <?
    $query 
    mysql_query("select * from $table"$db);
    $count mysql_affected_rows($db);

    for(
    $i 0$i $count$i++)
    {
        if(
    $i 10){
        list(
    $title,$date,$poster,$mail,$news) = mysql_fetch_row($query);
        
    $print  "<b>$title</b> by <a href=\"mailto:$mail\">$poster</a>";
        
    $print .= "<hr>";
        
    $print .= "$news<br><br>";
        echo 
    $print;
        }
    }
    mysql_close($db);
    ?>
    Is it possible to sort the news on date? The $date var has as format: yyyy-mm-dd
    Any suggestions?

  2. #2
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just change the query to
    SELECT * FROM $table ORDER BY date_column DESC
    i dunno...

  3. #3
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh, is that all? Thank you!
    I'm a newbie in mysql you know


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
  •