Results 1 to 4 of 4
  1. #1

    Reversing an Array


    I have a database of user posts for a very simple blog script I wrote. Just wondering how I would go about reading the database starting at the last record and moving towards the first.

    I know of the functions array_flip() and array_reverse() but am unsure how to actually use them properly.

    Here is the code as it stands:
    PHP Code:
    <table width="100%" border="0">

    while ($row mysql_fetch_array($result)) {
        <span class="subtitle"><? echo "{$row['title']}"?></span><br>
        <span class="post_info">Date: <? echo "{$row['date']}"?><br>
        Posted By: <? echo "{$row['poster']}"?></span>
        <? echo "{$row['post']}"?>
        <td height="10">&nbsp;

    <?php //end while loop ?>


  2. #2
    why don't you just use "order by desc" in your sql command?

  3. #3
    Join Date
    May 2004
    You should use:
    $array = array_reverse($array);

    But artofmobile has a good point, that this logic would be better moved to the database.
    char*s="#include<cstdio>%cchar*s=%c%s%c;%cint main(){std::printf(s,10,34,s,34,10);}";
    int main(){std::printf(s,10,34,s,34,10);}

  4. #4
    good point, worked perfeclty *slaps forhead*


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts