Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Moving through a MySQL DB 1

Status
Not open for further replies.

TheConeHead

Programmer
Joined
Aug 14, 2002
Messages
2,106
Location
US
Where with asp and SQL I can say rs.MoveNext(); to move from one record to the next, how would I do that with MySQL and PHP?

[conehead]
 
There is no exactly equivalent to MoveNext and (I assume the existence of) MovePrev. PHP's builtin functions are not object-oriented.

There are two ways to move through a MySQL return recordset.

First is to traverse them in order. The mysql_fetch_[row|assoc|array|object]() functions fetch a row and move the recordset pointer to the next record. A simple while() loop is all that is needed, as demonstrated in the example code here:
Second is random-order traversal. You do this by using mysql_data_seek(). There is example code on the PHP online manual page for mysql_data_seek():

Generally, I recommend using the in-order traversal and ordering the recordset through the use of SQL "WHILE" clauses.


Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top