|
Posted by frizzle on 12/13/06 13:20
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?
> Thanks,
>
> Lenard.
Be sure to set what field to order by, what order (DESC/ASC), and to
limit it to five, use LIMIT=5
Good luck!
[Back to original message]
|