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. 3 1209
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!
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.
Erwin Moller wrote:
SELECT firstname, lastname FROM tblusers ORDER BY lastname DESC LIMIT 10
Thanks, it's so simple... Problem is finding where in the docs... But
this worked very well, thanks. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Gleep |
last post by:
Hey Guys,
I've got a table called Outcomes. With 3 columns and 15 rows
1st col 2nd col 3rdcol
outcome date price
There are 15 rows...
|
by: hunglm |
last post by:
Hi all,
I'm trying to get the latest URL that a user visited in the frame.
But it just doesn't work.
function setURL() {
//document.cc.fm.URL.value=document.main.location.href;...
|
by: Taxi Driver |
last post by:
Does anyone know of a good script to gather email addresses from a
specific web site.
Thank you.
|
by: Ed L. |
last post by:
I'm trying to unsuccessfully to drop a database using the latest
CVS code for 8.0.0, getting the following error:
ERROR: cannot drop the currently open database
So I must have a connection...
|
by: Scott Frankel |
last post by:
Still too new to SQL to have run across this yet ...
How does one return the latest row from a table, given multiple entries
of varying data?
i.e.: given a table that looks like this:
color...
|
by: clare at snyder.on.ca |
last post by:
I have a SQL query I need to design to select name and email addresses
for policies that are due and not renewed in a given time period. The
problem is, the database keeps the information for every...
|
by: TGEAR |
last post by:
Itemlookup table
Field names : index_id (primary key), itemno, description.
It has a child table, which is ItemPriceHistory table
The relationship to the child table is one (parent table)-to-many...
|
by: Eugene |
last post by:
Hi all,
I have the following table
Name Date Wish Valid
Name is person's name, date defaults to getdate() and is never
assigned directly (datetime field), Wish is some message, and...
|
by: crimanysakes |
last post by:
Someone should write a FAQ on how to grab various "latest dates" from MySQL; cuz I'm quite confused.
Not sure how much to include; but here' my query to get my first "subset" of data:
select...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |