php - mysql_fetch_array while loop -


i have while loop contains while loop. both loops iterating on different mysql result sets. problem second time outer while loop calls inner while loop doesn't run. mysql_fetch_row discard after has been iterated over?

here code looks like:

$counter = 0; while ($r = mysql_fetch_row($result)){     $col = "";     $val = "";     while($d = mysql_fetch_row($dictionary)){         $key = $d[0];         for($i= 0; $i< count($tablecolumnames); $i++){             if($tablecolumnames[$i] == $key){                 $col .= "`".$d[1]."` ,";                 $val .= "`".$r[$i]."` ,";                 /* echo $tablecolumnames[$i]." table columnname <br>";                 echo $d[1]." key<br>"; */                            }                    }         echo $key."round".$counter."<br>";     }     var_dump ($col);     var_dump ($val);     $counter++;     echo $counter; } 

and here output like: can see $result holds 4 records , output showing loop working correctly. however, inner loop on $dictionary result set doesn't run second time $result being iterated over. ideas why? tried use mysql_fetch_array still same result.

thanks

enter image description here

when ever calling mysql_fetch_row($dictionary) gives particular column details in row , deletes $dictionary array.

so there no elements next use.

instead of declaring $dictionary outside declare in while loop. solve problem.

$counter = 0; while ($r = mysql_fetch_row($result)){ $col = ""; $val = ""; $dictionary=("select * database");//your own logic while($d = mysql_fetch_row($dictionary)){     $key = $d[0];     for($i= 0; $i< count($tablecolumnames); $i++){         if($tablecolumnames[$i] == $key){             $col .= "`".$d[1]."` ,";             $val .= "`".$r[$i]."` ,";             /* echo $tablecolumnames[$i]." table columnname <br>";             echo $d[1]." key<br>"; */                        }                }     echo $key."round".$counter."<br>"; } var_dump ($col); var_dump ($val); $counter++; echo $counter; } 

or can use mysql_data_seek().


Comments

Popular posts from this blog

database - VFP Grid + SQL server 2008 - grid not showing correctly -

jquery - Set jPicker field to empty value -

.htaccess - htaccess convert request to clean url and add slash at the end of the url -