Link to home
Start Free TrialLog in
Avatar of Passionate
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!
Avatar of lozloz
lozloz

could you be a bit more specific as to which while you can't do? and if it has no fetch array, how are you loading the data into your script from the database?

loz
Avatar of Passionate

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/webmonkey/99/31/stuff3a/functions.html

I need to convert the while/list() loops to foreach()
SOLUTION
Avatar of lozloz
lozloz

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial