[SOLVED] Show only last 10 items

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Show only last 10 items

Post by Revan »

Hello, i was wondering, IF i made a Forum script, how would i make it so it only shows the last ...10 threads? ive always wondered this, i know you use a WHILE
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

you could do in your query

Code: Select all

<?php

$result = @mysql_query("SELECT * posts_table ORDER BY `date` DESC LIMIT 10");

?>
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

Thank you, ill try it on my new script.
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Phenom wrote:you could do in your query

Code: Select all

<?php

$result = @mysql_query("SELECT * posts_table ORDER BY `date` DESC LIMIT 10");

?>
Why do you always use @function?

Bad habit.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

I'm sorry :*(

let me jus add this tho

Code: Select all

<?php

$result = mysql_query("SELECT * posts_table ORDER BY `date` DESC LIMIT 10") or die("Query Error: ".mysql_error()) ;

?>
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

Just for fun,

Will PHP be very confused and have existential problems if you do the following?

Code: Select all

$result = @mysql_query("SELECT * posts_table ORDER BY `date` DESC LIMIT 10") or die("Query Error: ".mysql_error()) ;
I mean we are suppressing all errors, yet we ask it to die.

Hehe, okay okay, i am sorry, that was lame...
User avatar
evilmonkey
Forum Regular
Posts: 823
Joined: Sun Oct 06, 2002 1:24 pm
Location: Toronto, Canada

Post by evilmonkey »

You're not asking for a PHP error, but a MySQL error...should work (Just my thoughts, haven't actually tried it out).
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post by d3ad1ysp0rk »

Yes, it will work.
Revan
Forum Commoner
Posts: 83
Joined: Fri Jul 02, 2004 12:37 am
Location: New Mexico, USA
Contact:

Post by Revan »

I tryed it, but it still showed more then 10

:/

edit: nvm i fixed it
Post Reply