2016-07-25 60 views
-2

我正在处理下面的PHP脚本,我想通过使用php变量设置td高度和列,我无法弄清楚如何执行。任何提示和帮助,以帮助我解决它是不胜感激。谢谢。无法使用php variabile设置html表格高度和宽度

<?php 

$n = 5; 
$table_height = 100; 

?> 

<!DOCTYPE html> 
<html> 
    <head> 
     <title>Your Table is Ready</title> 
    </head> 
    <body> 
     <table> 
      <?php for ($i = 0; $i < $n; $i++): ?> 
      <tr> 
       <?php for ($x = 0; $x < $n; $x++): ?> 
       <td height="{$table_height}"; width = "{$n}"><?php print($i * $x) ?></td> 
       <?php endfor ?> 
       </tr> 
      <?php endfor ?> 
     </table> 
    </body> 
</html> 
+1

首先,你的变量不在PHP块内。另一方面,使用style属性会比'height'和'width'好,尽管它可能不如您期待的那样有效。 –

回答

1

变化

<td height="{$table_height}";...> 

<td height="<?= $table_height ?>px";...> 

你可能需要做单元格的宽度相同。 {$var}实际上并不打印PHP值。你需要php括号<?= ?>来回显。

+0

感谢@BeetleJuice解决了我的问题。 – user3221699