Jump to content

Archived

This topic is now archived and is closed to further replies.

Guest edwinsweep

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.

Share this post


Link to post
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.

Share this post


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

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.

×

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.