Jump to content


Extracting Database Results With PHP


  • This topic is locked This topic is locked
2 replies to this topic

#1 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 07 July 2006 - 12:00 PM

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.
while ($row= mysql_fetch_array($result)) {
$row['dbcolname']
}
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.

#2 hvle

hvle
  • Members
  • PipPipPip
  • Advanced Member
  • 667 posts
  • Locationmelbourne, Australia

Posted 07 July 2006 - 12:10 PM

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.
Life's too short for arguing.

#3 Guest_edwinsweep_*

Guest_edwinsweep_*
  • Guests

Posted 07 July 2006 - 12:13 PM

thanks for the answer.
a lot clearer now.
simple question simple answer:) :) :)
thanks and cya later!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users