PHP how to print proper column td1 td2 td3 output?
I am trying to output a table using php variables like this:
echo "<tr>";
echo "<td>".$var1."</td开发者_JAVA百科>";
echo "<td>".$var2."</td>";
echo "</tr>";
It works fine if both variables exist.. but if $var1 is null, the $var2 value is outputted to the firs column in the HTML table. Is there a way to properly output the columns by naming them? P.S: I can't do "if $var == NULL ...." for some coding reasons. I want to control the HTML output if possible.
While I agree with @leeb above, do you want something like this:
echo "<td>" . isset($var1)?$var1:"" . "</td>";
echo "<tr>";
echo "<td>".$var1." </td>";
echo "<td>".$var2." </td>";
echo "</tr>";
精彩评论