Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP Using MYSQL over ADODB Query

Status
Not open for further replies.

yumbelie

Programmer
Dec 31, 2002
96
GB
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 &quot;FirstName is: $row->cust_fname<BR>&quot;;
echo &quot;LastName is: $row->cust_lname<BR>&quot;;


/*

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 &quot;<option value='$coderow->code_id'>$coderow->code_id&quot;;
}
}

$code->Move(0);

while ($coderow = $moo->FetchNextObj())
{
if ($coderow->$code_id == $row->cust_code)
{
echo &quot;<option value='$coderow->code_id'>$coderow->code_id&quot;;
}
}


Anyway, *any* help would be appericated, this works, but I don't like not knowing why.

Thanks Guys

Yum.


 
A quick correction, the second while statement should read:

while ($coderow = $moo->FetchNextObj())
{
if ($coderow->$code_id != $row->cust_code)
{
echo &quot;<option value='$coderow->code_id'>$coderow->code_id&quot;;
}
}

i.e. it should be != not ==. Also the word: 'assing' means 'assign'.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top