Results 1 to 4 of 4
  1. #1

    Reversing an Array

    Hello,

    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">

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

    <?php //end while loop ?>


    </table>
    Thanks.

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

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

    But artofmobile has a good point, that this logic would be better moved to the database.
    #include<cstdio>
    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*

    Thanks

Posting Permissions

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