I am trying to create a PHP script that queries entries from a MySQL
table:
<?php
$user="myuserna me";
$password="mypa ssword";
$database="myda tabase";
mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query = "SELECT ititle, inumber FROM nucleus_item";
$result = mysql_query($qu ery);
while($row = mysql_fetch_arr ay($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.
table:
<?php
$user="myuserna me";
$password="mypa ssword";
$database="myda tabase";
mysql_connect(l ocalhost,$user, $password);
@mysql_select_d b($database) or die( "Unable to select database");
$query = "SELECT ititle, inumber FROM nucleus_item";
$result = mysql_query($qu ery);
while($row = mysql_fetch_arr ay($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.
Comment