Jump to content

Archived

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

whare

Only show "x" results

Recommended Posts

Hi All Me again :)

right im trying to work out how to show only the newest entries into the sql db basicly like a preview of what has happend latly but i have no idea how to do (I no I need to get a php book lol well I got one on order lol)

so can anybody tell me how or point me towards something that tells me how

Thanx

Whare

[sorry no code to show you what i got not started working on it yet]

Share this post


Link to post
Share on other sites
Instead of:
[code]
while($row=mysql_fetch_row($result))
{
//Some code
}
[/code]
Use:
[code]
$shown=0;
$toshow=12;
while($row=mysql_fetch_row($result))
{
if($show<=$toshow)
{
//Some code
}
}
[/code]


To show the most RECENT mysql rows, put desc after the ORDER BY id bit. (ORDER BY id desc)

EDIT: You can change $toshow=12 to $toshow=the number of rows you want to show.

Share this post


Link to post
Share on other sites
If you just want, say, the 10 latest,

[code]SELECT blah1, blah2 FROM mytablename ORDER BY id DESC LIMIT 10[/code]

Share this post


Link to post
Share on other sites
@alecjw,

You need to increment $show (or $shown depending on which variable name you finally settle on)

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.