Passionate
asked on
foreach -to- while
I need to covert a threaded (recursive) comment system from PHP/MySQL -to- PHP/ADOdb. However, I am having minor problems with using foreach() loops instead of while() loops, because ADOdb has no "fetch array" functions per say.
Instead of "posting" all of the code:
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/functions.html
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/display_topic.html
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/write_topic.html
"Any help at all" would be greatly appreciated!
Instead of "posting" all of the code:
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/functions.html
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/display_topic.html
http://hotwired.lycos.com/webmonkey/99/31/stuff3a/write_topic.html
"Any help at all" would be greatly appreciated!
ASKER
Ok, quick example
************************** ********** ********** *
PHP/MySQL
************************** ********** ********** *
<?php
$query = 'SELECT var, var2 FROM table';
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result) ) {
extract($row);
echo $var . '<BR />' . $var2;
}
?>
************************** ********** ********** *
PHP/ADOdb
************************** ********** ********** *
<?php
$query = 'SELECT var, var2 FROM table';
$results = $db->GetAll($query) or die($db->ErrorMsg());
foreach($results AS $row) {
extract($row);
echo $var . '<BR />' . $var2;
}
?>
************************** ********** ********** *
Now look at the first script here
ttp://hotwired.lycos.com/w ebmonkey/9 9/31/stuff 3a/functio ns.html
I need to convert the while/list() loops to foreach()
**************************
PHP/MySQL
**************************
<?php
$query = 'SELECT var, var2 FROM table';
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_assoc($result)
extract($row);
echo $var . '<BR />' . $var2;
}
?>
**************************
PHP/ADOdb
**************************
<?php
$query = 'SELECT var, var2 FROM table';
$results = $db->GetAll($query) or die($db->ErrorMsg());
foreach($results AS $row) {
extract($row);
echo $var . '<BR />' . $var2;
}
?>
**************************
Now look at the first script here
ttp://hotwired.lycos.com/w
I need to convert the while/list() loops to foreach()
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you lozloz, but I am afraid that did NOT work, no errors - just a blank page. Note when you INSERT or UPDATE in ADOdb use the Execute() function rather than the GetAll() function which is for a SELECT.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
loz