title: PHP while loop and table header only showing if a db value is set
body: <p>Here is my code.</p>
  
  <pre><code>&lt;table border="1" style="width:800px"&gt;
                  &lt;?php $schedule_db = mysql_query("SELECT * FROM schedule WHERE '00:00' is not null and '01:00' is not null and '02:00' is not null and '03:00' is not null and '04:00' is not null and '05:00' is not null and '06:00' is not null and '07:00' is not null and '08:00' is not null and '09:00' is not null and '10:00' is not null and '11:00' is not null and '12:00' is not null and '13:00' is not null and '14:00' is not null and '15:00' is not null and '16:00' is not null and '17:00' is not null and '18:00' is not null and '19:00' is not null and '20:00' is not null and '21:00' is not null and '22:00' is not null and '23:00' is not null") 
                  or die(mysql_error()); ?&gt;
                  &lt;form method="post" action="config_action.php"&gt;
                  &lt;?php while($schedule = mysql_fetch_array( $schedule_db )) { ?&gt;
                      &lt;tr&gt;&lt;?php if(isset($schedule['00:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['00:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['02:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['02:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['03:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['03:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['04:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['04:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['05:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['05:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['06:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['06:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['07:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['07:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['08:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['08:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['09:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['09:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['10:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['10:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['11:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['11:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['12:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['12:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['13:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['13:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['14:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['14:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['15:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['15:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['16:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['16:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['17:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['18:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['19:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['19:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['20:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['20:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['21:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['21:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['22:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['22:00'] ?&gt;&lt;/td&gt;&lt;?php } if(isset($schedule['23:00'])) { ?&gt;&lt;td style="width:32px"&gt;&lt;?php echo $schedule['23:00'] ?&gt;&lt;/td&gt;&lt;?php } ?&gt;&lt;/tr&gt;
                  &lt;?php } ?&gt;
                  &lt;/form&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>What I want to do is a have a table header (just a row above all the other rows) that shows what time each column is but only if there is a value in the column.</p>
  
  <p>I thought I code to something like:</p>
  
  <pre><code>&lt;tr&gt;&lt;?php if(isset($schedule['00:00'])) { ?&gt;&lt;td style="width:32px"&gt;00:00&lt;/td&gt;&lt;?php } if(isset($schedule['01:00'])) { ?&gt;&lt;td style="width:32px"&gt;01:00&lt;/td&gt;&lt;?php } ?&gt; etc.
  </code></pre>
  
  <p>However because it is in a while loop, it will happen before every actual row, which isn't what I want to happen, I just want it to happen once on the top.</p>
  
  <p>How can I solve this problem? Is there something I could append to that to make it only loop once?</p>
  
  <p>Thanks!</p>