1) Add an ORDER BY into the sql query.
2) Get the results into an array and use array_reverse().
3) Store what your eching into a string and add the new results to the start of the string instead of the end - so the last result is first in the string:
Would it be possible to see the code that worked in this situation? I have a similar situation on the back burner. It's there because I couldn't figure out how to get it to work.
<?php
// code left out above...reply if you need it (I kind of doubt you'll need it, though)
$query="SELECT * FROM news_posts ORDER BY id DESC";
$result=mysql_query($query,$link);
$numrows=mysql_num_rows($result);
for($i=0; $i<$numrows; $i++){
$the_arrays=mysql_fetch_array($result);
print("<br /><h2 class="sub">{$the_arrays['title']}</h2>\n");
print("<br /><span style="font-size:8pt;">posted: <i>{$the_arrays['date']}</i>"
."\nID: <i>{$the_arrays['id']}</i></span>\n");
print("<br />{$the_arrays['posttext']}");
}
?>
welcome
I did have it
$query="SELECT * FROM news_posts"
."ORDER BY id DESC";
but I got a sytax error because it didn't recognize any space between news_posts and ORDER so I just put it on one line.
I'm sort of a "noob" myself (at SQL). I am getting the hang of it now. I already knew PHP and I finally found a use for SQL so I'm learning it.
I first used SQL in the days of R:base and Clarion. Therefore, I had a pretty good start in basic MySQL, although there are significant differences from the SQL of ten years ago vs MySQL4 today.
Because of the difference, I get cornered a lot using invalid statements and such.
Since PHP was the natural companion for MySQL, I got to jump in with both feet about a year ago. I mostly insert PHP scripts and my own images (my first love) into other peoples' HTML. My PHP level is pretty low, but fortunately, I don't have to write whole pages using it like the folks who wrote this forum package.