Hi, I have a few rows in a DB stored w/ a datetimecol. I am able to select one row by using this code: $sql = mysql_query("select title from news order by datetimecol desc limit 1"); while ($row = mysql_fetch_assoc($sql)) { echo "<br /><span style=\"background-color: blue\"><b>The newest news article is: $row[title] </b></span>"; } PHP: But now I want to output the `title` of each row in descending order by the datetimecol ( newest being at the top ). How could I do this?
Thanks but I accidentally posted the wrong code! for($x = 0; $x<$result; $x++) { $sql = mysql_query("select title from news order by datetimecol desc"); $row = mysql_fetch_assoc($sql); echo "$row[title] <br />"; } PHP:
change this: $row = mysql_fetch_assoc($sql); echo "$row[title] <br />"; PHP: to this: while($row = mysql_fetch_array($sql)) { echo "$row[title] <br />"; } PHP: This was one of the hardest things for me to learn when I first started with mySQL - you're on the right track!