Noobster Noobster - 1 year ago 75
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

$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>";

Is this even possible?

Answer Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download