Log in

View Full Version : MySQL getting info to index.php



Total_me
02-23-2010, 11:42 AM
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

Schmoopy
02-23-2010, 05:30 PM
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

$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'];
}

?>