Jump to content

dynamic selection of content - ermm... help!


stuart.cole

Recommended Posts

Hi

I am building a news delivery site - with the news being delivered in 3 areas. The first should have the latest news item, the second area the second most recent item, and the third area, latest stories 3-7.

How can I get PHP to select the last item, next to last, and then 3-7 since the ID's of these items will change as new items are added all the time?

I know there is probably a very simple answer to this - but I've not found one yet :(
Link to comment
Share on other sites

Like so:

Area 1: Latest
[code]<?php
$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 0,1';
?>[/code]

Area 2: 2nd Latest
[code]<?php
$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 1,1';
?>[/code]

Area 3: Results 3 to 7
[code]<?php
$query = 'SELECT * FROM "news" ORDER BY "date" DESC LIMIT 2,5';
?>[/code]

...replacing [code=php:0]'news'[/code] and [code=php:0]'date'[/code] with whatever your columns are named. You might also want to read the suggested documentation to know how everything works. :)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.