Jump to content

Extracting Database Results With PHP


Guest edwinsweep

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
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.
Link to comment
Share on other sites

Guest edwinsweep
thanks for the answer.
a lot clearer now.
simple question simple answer:) :) :)
thanks and cya later!
Link to comment
Share on other sites

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.