Select specific record

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
thomas49th
Forum Newbie
Posts: 11
Joined: Wed Aug 04, 2010 4:29 pm

Select specific record

Post by thomas49th »

Hi, I could use

while($row = mysql_fetch_rows($result)){
echo "{$row[0]};";
}

and that would echo the first field of all records found

BUT what is I want to select a specific record. Ie the 5th one down. I cannot do
$row = mysql_fetch_rows($result)
echo "{$row[4][0]};";

or echo "{$row[0][4]};";

How do I achieve what I want to do

Thanks
Thomas
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Select specific record

Post by superdezign »

You would specify that in your query.

Code: Select all

select * from `table_name` limit 1, 5
Also, I don't think mysql_fetch_rows() is a real function...
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Select specific record

Post by AbraCadaver »

I'm not sure why you want to do this, but in general superdezign is spot on. Retrieve what you need in the query. However, if you need many rows, but just for a certain piece of code you need a specific row then use: mysql_data_seek().
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
thomas49th
Forum Newbie
Posts: 11
Joined: Wed Aug 04, 2010 4:29 pm

Re: Select specific record

Post by thomas49th »

No No, I can get the records out I want using

while($row = mysql_fetch_rows($result)){
echo "{$row[0]};";
}

to print them out, but I want to just print a specific one, for example record number 3... not all 6. Out of the records found, how do I select a specific one to print to screen



Thanks
Thomas :)
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Select specific record

Post by AbraCadaver »

thomas49th wrote:No No, I can get the records out I want using

while($row = mysql_fetch_rows($result)){
echo "{$row[0]};";
}

to print them out, but I want to just print a specific one, for example record number 3... not all 6. Out of the records found, how do I select a specific one to print to screen
)
Just what I told you :)

Code: Select all

mysql_data_seek($result, 4);
$row = mysql_fetch_array($result);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
thomas49th
Forum Newbie
Posts: 11
Joined: Wed Aug 04, 2010 4:29 pm

Re: Select specific record

Post by thomas49th »

Ahh sorry :oops:

Will try tomorrow :)
Thanks
Thomas
Post Reply