Jump to content

Extracting Database Results With PHP


Recommended Posts

Guest edwinsweep
hi everybody.
i wonderred if there are more ways than mine to show your database query results.
the only way i know is the while loop like this.
[CODE]
while ($row= mysql_fetch_array($result)) {
$row['dbcolname']
}
[/CODE]
i have been trying to get it to work with a foreach loop.
but i couln't get it to work.
is it because its not possible, or am i just doing something wrong.
and why do i have to put the mysql_fetch_array in the while loop, and not just a variable name that contains the fetch thing?
if anybody could help me out and clarifie this for me, it would be a great help.
thanks in advance.
Link to comment
https://forums.phpfreaks.com/topic/13942-extracting-database-results-with-php/
Share on other sites

Resultset is a resource type, not an array type, so you can not foreach.
Resultset contain an internal pointer.  This pointer points to the current row.
When you mysql_fetch, result return the current row, then increment this pointer.
when result set is query, the pointer pointed at first row or row-0.

mysql_data_seek($result, $row); will set the pointer to the row you wanted.
and yes, you have to use a function to retrieve data in result.
There're many of them.
Guest
This topic is now closed to further replies.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.