Page 1 of 1

Two Simultaneous While Loops?

Posted: Sun Feb 12, 2006 8:49 pm
by VmusicV
Hi,
I want to loop through either a) A result set or b) an array only once so I can process the elements once in code? is there a way to do this?



So... ahead of time, while I'm writing the code, I can't tell which 'condition' will exist. Either I'll need to loop through a query result, or loop through an array. The way or the code I use to process either will be the same, but I can't figure out how to make two simultaneous/conditional loops?


Any Ideas?

maybe one idea is to call out a common function from within each of loops separately?

Code: Select all

if($condition_to_use_query === true){
     //// query the data into $result
     while($row  =  mysql_fetch_array($result))
     {
          displayElement($row[0]);
     }
}else{
     ///loop through the array
     foreach($my_array as $key => $value){
              displayElement($row[0]);
     }
}


Any other ideeeeers?

VmusicV

Posted: Sun Feb 12, 2006 8:56 pm
by Jenk