What I have is PHP (4.3.1) running over ADODB to interface with MySQL 4.0. Now, as I understand it, when you perform a $db->Execute("QUERY"
; in PHP using ADODB functions, it gets the record set and stores it as an associative array. This is, I perform the following:
$result = $db->Execute("SELECT * FROM customers"
;
$row = $result->FetchNextObj(); // No While, as I only want first record.
$code = $db->Execute("SELECT DISTINCT code_id FROM code"
;
echo "FirstName is: $row->cust_fname<BR>";
echo "LastName is: $row->cust_lname<BR>";
/*
Now this is where it gets thorougly confusing, the code below works, but I haven't a clue why, and it was just pot luck it seems... Basically, I copy the $code array into $moo variable (preivously undeclared). Then execute a simple while loop on $code to retreive the row info, so I can populate the dropdown box. Now, this is where it gets confusing, I reset the pointer in the $code array to point to the first record, I make no further use of it. I then use $moo array to populate the remainder of the <option>'s. Now, why does resetting the record pointer in $code cause $moo to work? (It doesn't if I don't, it only displays a single record - their are 4 in total, 3 when the one that is already displayed by the first while statement is counted). And also, why do I have to assing $code to $moo anyway? surely just resetting the $code move pointer before performing another while should be enough - if even that step is necessary? This is totally confusing, because as I see it, performing the $code->Move(0) should make *no* difference at all, seeing as $code is never called again...
$moo = $code;
while ($coderow = $code->FetchNextObj())
{
if ($coderow->$code_id == $row->cust_code)
{
echo "<option value='$coderow->code_id'>$coderow->code_id";
}
}
$code->Move(0);
while ($coderow = $moo->FetchNextObj())
{
if ($coderow->$code_id == $row->cust_code)
{
echo "<option value='$coderow->code_id'>$coderow->code_id";
}
}
Anyway, *any* help would be appericated, this works, but I don't like not knowing why.
Thanks Guys
Yum.
$result = $db->Execute("SELECT * FROM customers"
$row = $result->FetchNextObj(); // No While, as I only want first record.
$code = $db->Execute("SELECT DISTINCT code_id FROM code"
echo "FirstName is: $row->cust_fname<BR>";
echo "LastName is: $row->cust_lname<BR>";
/*
Now this is where it gets thorougly confusing, the code below works, but I haven't a clue why, and it was just pot luck it seems... Basically, I copy the $code array into $moo variable (preivously undeclared). Then execute a simple while loop on $code to retreive the row info, so I can populate the dropdown box. Now, this is where it gets confusing, I reset the pointer in the $code array to point to the first record, I make no further use of it. I then use $moo array to populate the remainder of the <option>'s. Now, why does resetting the record pointer in $code cause $moo to work? (It doesn't if I don't, it only displays a single record - their are 4 in total, 3 when the one that is already displayed by the first while statement is counted). And also, why do I have to assing $code to $moo anyway? surely just resetting the $code move pointer before performing another while should be enough - if even that step is necessary? This is totally confusing, because as I see it, performing the $code->Move(0) should make *no* difference at all, seeing as $code is never called again...
$moo = $code;
while ($coderow = $code->FetchNextObj())
{
if ($coderow->$code_id == $row->cust_code)
{
echo "<option value='$coderow->code_id'>$coderow->code_id";
}
}
$code->Move(0);
while ($coderow = $moo->FetchNextObj())
{
if ($coderow->$code_id == $row->cust_code)
{
echo "<option value='$coderow->code_id'>$coderow->code_id";
}
}
Anyway, *any* help would be appericated, this works, but I don't like not knowing why.
Thanks Guys
Yum.