开发者

PHP how to print proper column td1 td2 td3 output?

开发者 https://www.devze.com 2023-02-12 16:02 出处:网络
I am trying to output a table using php variables like this: echo \"<tr>\"; echo \"<td>\".$var1.\"</td开发者_JAVA百科>\";

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."&nbsp;</td>";
echo "<td>".$var2."&nbsp;</td>";
echo "</tr>";
0

精彩评论

暂无评论...
验证码 换一张
取 消