Noobster Noobster - 3 months ago 10
PHP Question

php - how to exclude a line of code in a loop

I have a code in HTML in a table. And I want the loop to just ignore them

<?php
$sel_admin = "query ";
$rs_admin = mysql_query($sel_admin);
while($row = mysql_fetch_array($rs_admin))
{
echo "<th>". $row['a']. "</th>";


</thead> // This two line of code
<tbody> // is the one I want to exclude in the while loop


$sel_admin2 = "query2 ";
$rs_admin2 = mysql_query($sel_admin2);
while($row2 = mysql_fetch_array($rs_admin2))
{
echo" <tr class='gradeX'> ";
echo "<td>" . $row2['sched3_time']. "</td>";
echo"</tr>";
}
}
?>


Is this even possible?

Answer

I'm guessing you want those lines printed once, not to be outside the loop, per se. You could use a variable to track it:

$linesNeeded = true;
while (...) {
  ...
  if ($linesNeeded) {
    echo $line1;
    echo $line2;
    $linesNeeded = false;
  }
  ...
}