Jump to content

[SOLVED] Fetch array but skip the first few results?


FridayRain

Recommended Posts

I've tried Googling but I must not know the proper words to include. I'm thinking this is simple math. Something like adding 1 to a variable such as $id.

 

My main page will display blog entries, but my right column display the titles of the four most recent pieces from each category, including the blog. Since this column is on every page, there's no need to display blog entries that are already on the front page, so I'd like the query to skip the first three entries and start with the fifth most recent.

 

This is the code for the right column pulling blog entry titles:

 

<?php
require("db/config.php");
require("db/opendb.php");

    $query = "SELECT * FROM blog ORDER BY date DESC LIMIT 4";
    $result = mysql_query($query);

    while($row = mysql_fetch_assoc($result))
        {
        $titlesb[] = "<span>+ </span><a href=\"blogs.php?piece={$row[id]}\">{$row[title]}</a>";
        }

require("db/closedb.php");

    echo implode('<br />', $titlesb);

?>

Have you tried echoing out the <span> tags inside the while loop as they are generated instead of storing them in an array and doing an implode? I'm not familiar with the implode command so it might work fine but it could be worth a try.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.