I cannot seem to get foreach to work. Maybe I do not understand it correctly.Here is my code:\[code\]$statement = "SELECT * FROM categories ORDER BY name ASC";$query = mysql_query($statement)......$cals = array("sports","general","other","clubs");foreach ($cals as $value){/* echo "<h3>".$value."</h3>"; */ echo "<table width='100%'>";while ($array = mysql_fetch_array($query)) { if ($array['calendar'] == $value) {?><tr> <td><?php echo $array['name']; ?></td> <td><a onclick="update_form('<?php echo $array['name']; ?>', '<?php echo $array['calendar']; ?>')" href="http://stackoverflow.com/questions/3740296/#">Edit</a></td></tr><?php } } echo "</table><br />Value: $value";}\[/code\]The goal of this is to have the foreach change the if statement. I had planned for the if statement to say: \[code\]if ($array['calendar'] == "sports")\[/code\] the first time, \[code\]if ($array['calendar'] == "general")\[/code\] the second time, and so on. However, it shows all of the tables (in the source code), but no table rows are created after the first for each array value. For example, I correctly see the sports table, but I do not see any table rows for general, other, or clubs. There are records in that database that should appear in each of those. Could it be a problem with the while and if statements? If I manually set the $value in the if statement to one of the values in the array, it shows the correct records.What am I missing?Sample Data:in the MySQL database - categories table.fields:
- id
- name
- num_events
- calendar
- calendar_url