Page 1 of 1

newbie question about fetch_array

Posted: Sat Sep 17, 2005 12:56 pm
by svenxie
feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Code: Select all

$myc = mysql_connect("localhost", "root", "");
mysql_select_db("mydatenbank", $myc);

$query1 = mysql_query("SELECT A.LRUsername, A.LRPassword
FROM community A
WHERE A.LRUsername NOT IN
(SELECT user FROM arsc_registered_users)
", $myc);

while ($result = mysql_fetch_array($query1))
{

echo $result["LRUsername"]." <br />\n ";
echo $result["LRPassword"]." <br />\n ";
}

how mysql_fetch_array works?
why does the pointer move by itself without FOR NEXT or sth like $i++?

and, is $result just for one row? and wait till the next turn of WHILE
when the pointer moves to next, it reads another row of data?


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Re: newbie question about fetch_array

Posted: Sat Sep 17, 2005 1:02 pm
by feyd
svenxie wrote:how mysql_fetch_array works?
mysql fetch array returns, unless specified, will return an array of both numeric and named indices of the current row (if available)
svenxie wrote:why does the pointer move by itself without FOR NEXT or sth like $i++?
the result resource keeps a pointer to which row it is currently on of the result set. This internal row pointer is advanced on each call to a fetch function.
svenxie wrote:and, is $result just for one row? and wait till the next turn of WHILE
when the pointer moves to next, it reads another row of data?
In your instance of code, $result is one row on each call to mysql_fetch_array() until there are no more rows to fetch, in which case it will be false.

Posted: Sat Sep 17, 2005 2:42 pm
by svenxie
thank you very much.

sorry that i'm new here and not familiar to the rules,
also new to php.

thanks again.

Posted: Sat Sep 17, 2005 6:45 pm
by s.dot
I would say use mysql_fetch_assoc, being new, unless you specifically need indiced arrays.

that way, when debugging, you'll just see an array of associative values, like:

Code: Select all

Array (
   [field1] => fieldonevalue,
   [field2] => field2value,
   [etc] => more values
   )