Results 1 to 2 of 2

Thread: MySQL getting info to index.php

  1. #1
    Join Date
    Jul 2009
    Location
    Lithuania
    Posts
    25
    Thanks
    9
    Thanked 0 Times in 0 Posts

    Question MySQL getting info to index.php

    I'm got problem.. Em, actually not problem because I recieving info out of MySQL. However how to do, that in index.php would show be in top the lastest posted new or something else not in the bottom..

    for ex:
    [ in mysql:
    1. My name is Donatas
    2. Your name User
    3. ...
    in page:
    3. ...
    2. Your name User
    1. My name is Donatas. ]
    however now.. my index shows
    1. ...
    2. ...
    3. .....
    How to do like in examle? :S

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    You can order by date/time, if you have that as a field in your database.

    "name", "comment", "datetime" are the fields in the example.

    PHP Code:
    <?php

    $sql 
    "SELECT * FROM `comments` ORDER BY `datetime` DESC"// Get newest comments first
    $res mysql_query($sql) or die('Failed to query DB');

    while(
    $row mysql_fetch_array($res)) {
      echo 
    "Name: " $row['name'] . "<br />";
      echo 
    "Comment: " $row['comment'];
    }

    ?>

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
  •