|
Posted by Erwin Moller on 12/13/06 13:25
Lenard Redwood wrote:
> I am trying to create a PHP script that queries entries from a MySQL
> table:
>
> <?php
> $user="myusername";
> $password="mypassword";
> $database="mydatabase";
> mysql_connect(localhost,$user,$password);
> @mysql_select_db($database) or die( "Unable to select database");
> $query = "SELECT ititle, inumber FROM nucleus_item";
> $result = mysql_query($query);
>
> while($row = mysql_fetch_array($result, MYSQL_ASSOC))
> {
> echo "Name :{$row['ititle']} <br>" .
> "Subject : {$row['inumber']} <br>";
> }
> mysql_close();
> ?>
>
> What I'd like to do is to grab the 5 latest rows of the "inumber"
> field. This field starts from 1 and currently ends at 2100 but everyday
> there are new entries. So I think I should sort the table rows from the
> greatest number to the lowest, and take only the 5 latest entries. I
> didn't find on php.net how to do that. Any idea?
Hi,
You don't find it at php.net because you should have searched your mysql
documentation. :-)
The keyword you are looking for is LIMIT
example:
SELECT firstname, lastname FROM tblusers ORDER BY lastname DESC LIMIT 10
Regards,
Erwin Moller
> Thanks,
>
> Lenard.
[Back to original message]
|