Selecting certain rows in a mysql table.

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
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Selecting certain rows in a mysql table.

Post by mattyboi »

I would like to know if there is a way to select the first row in a table. Once I've selected and pulled out the info I needed from that first record, I then would like to select the next row in the table.

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:?

Code: Select all

$query = mysql_query('SELECT * FROM `table`);

while($row = mysql_fetch_assoc($query))
{
  // do stuff for each row.
}
mattyboi
Forum Commoner
Posts: 34
Joined: Mon Feb 06, 2006 9:42 pm

Post by mattyboi »

That works for all the rows in the table. I only would like to capture the first row and then the row following the first. I remember in SQL there was a next_row function and a previous_row function. I was wondering if there was something similar in mySQL.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

SELECT * FROM `table` LIMIT 2
Post Reply