SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Reversing this

  1. #1
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,782
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)

    Reversing this

    devwebsites.com/sitedevs/

    I have a PHP blog going, have to manually insert the articles though (ignore the broken layout, I will need to display the most recent 10 to not break the layout(only like 4 on there so far)

    Mind telling me how to make them display the opposite way?
    Code php:
    <div id="rightcolumn">
     <?
    if($num > 0){
    while($row_articles = mysql_fetch_assoc($blogarticles)){
    ?>
    <div class="blog">
    <span class="title"><?=$row_articles['title'];?></span>
    <span class="author">Posted by:<?=$row_articles['name'];?></span>
    <span class="date">The date posted: <?=$row_articles['date_posted'];?> </span>
    <div class="post"><?=$row_articles['comments'];?></div>
    </div>
    <?
    }
    }
    ?>
    </div>

    Any idea on how to make the most 10 recent show AND reverse the order ?
    Always looking for web design/development work.
    http://www.CodeFundamentals.com

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    Code:
    <div id="rightcolumn">
    
    
    <?php    
    if($num > 0) {
     
     
    $rows = array();
    while($row_articles = mysql_fetch_assoc($blogarticles)) {
    	array_unshift($rows,$row_articles);
    }
    
    foreach($rows as $row_articles) { ?>
    
    <div class="blog">
    <span class="title"><?=$row_articles['title'];?></span>
    <span class="author">Posted by:<?=$row_articles['name'];?></span>
    <span class="date">The date posted: <?=$row_articles['date_posted'];?> </span>
    <div class="post"><?=$row_articles['comments'];?></div>
    </div>
    
    <?php } 
    
    }
    ?>
    
    
    </div>
    The ideal solution would probably be to alter the query though.

  3. #3
    Theoretical Physics Student bronze trophy Jake Arkinstall's Avatar
    Join Date
    May 2006
    Location
    Lancaster University, UK
    Posts
    7,062
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Modifying the query is your best chance. Say you want to order it by the last post made.

    If the date_posted column is also a time, you can use this:
    Code sql:
    SELECT title, name, date_posted, comments FROM yourtable ORDER BY date_posted DESC LIMIT 10

    But if it only shows the date, and not the time
    Code sql:
    SELECT title, name, date_posted, comments FROM yourtable ORDER BY date_posted, id DESC LIMIT 10

    BTW, you are grabbing a value from the comments column - this is just like a description, right? If (as implied by the name) it's actually a load of comments made by users, I'd suggest modifying your table structure to have an extra table for comments, using the post ID as the reference.
    Jake Arkinstall
    "Sometimes you don't need to reinvent the wheel;
    Sometimes its enough to make that wheel more rounded"-Molona

  4. #4
    billycundiff{float:left;} silver trophybronze trophy RyanReese's Avatar
    Join Date
    Oct 2008
    Location
    Whiteford, Maryland, United States
    Posts
    13,782
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    The code posted above was just fine and dandy (first reply). I am deciding to just go it this way since the SQL stuff is shaky with me and that does the trick. I originally tried to do array_reverse but it had to be an array so I was confused as how to do it. Thanks.
    Always looking for web design/development work.
    http://www.CodeFundamentals.com


Bookmarks

Posting Permissions

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