Jump to content


Photo

Only show "x" results


  • This topic is locked This topic is locked
4 replies to this topic

#1 whare

whare
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 07 August 2006 - 07:55 PM

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]

#2 alecjw

alecjw
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts
  • LocationHatfield, Herts, UK

Posted 07 August 2006 - 08:13 PM

Instead of:
while($row=mysql_fetch_row($result))
{
//Some code
}
Use:
$shown=0;
$toshow=12;
while($row=mysql_fetch_row($result))
{
if($show<=$toshow)
{
//Some 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.

#3 whare

whare
  • Members
  • PipPipPip
  • Advanced Member
  • 75 posts

Posted 07 August 2006 - 08:17 PM

Thanx mate that should help me out alot


:)


#4 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 August 2006 - 08:24 PM

If you just want, say, the 10 latest,

SELECT blah1, blah2 FROM mytablename ORDER BY id DESC LIMIT 10

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts

#5 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 07 August 2006 - 08:29 PM

@alecjw,

You need to increment $show (or $shown depending on which variable name you finally settle on)
If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users