html - php while loops not executing properly -


i have 3 wards a,b,c in database , 4 employees (3 on ward a, 4 on b , 1 on c) , below script prints out wards correctly , prints out 3 employees works on ward nothing more (i:e compares against ward , not other 2) see image

can see obvious error in order php executing causes this? i'm new php thats why don't quite understand syntax =)

while ( $row = mysql_fetch_array($wardnames) ) {          echo("<tr><td><a href=\"javascript:displayward('" . $row['name'] ."')\">         <div class='wardheader'><div class='plus'></div><div class='wardname'><b>" . $row['name'] . " </b></div>         </div>         </a></td></tr>");          while ( $employeerow = mysql_fetch_array($employees)) {//only prints out employees on ward , not b or c. why?             if($employeerow['ward']==$row['name']){                 echo("<tr><td>" . $employeerow['name'] . "</td></tr>");              }         }     } 

after iterating on resultset it's exhausted , not iterable anymore. store in array before outer loop:

$all_employees = array(); while($row = mysql_fetch_array($employees)) {     $all_employees[] = $row; }  while ( $row = mysql_fetch_array($wardnames) ) {      echo("<tr><td><a href=\"javascript:displayward('" . $row['name'] ."')\">           <div class='wardheader'><div class='plus'></div><div class='wardname'><b>" . $row['name'] . " </b></div>           </div>           </a></td></tr>");      foreach($all_employees $employeerow)         if($employeerow['ward']==$row['name']){             echo("<tr><td>" . $employeerow['name'] . "</td></tr>");          }     } } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -