Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 什么';代码有什么问题吗_Php - Fatal编程技术网

Php 什么';代码有什么问题吗

Php 什么';代码有什么问题吗,php,Php,我对php非常陌生。我正在读一本书,书中有一个关于while循环的例子: <html> <body> <table border="0" cellpadding="3"> <tr> <td bgcolor="#CCCCCC" align="center">Distance</td> <td bgcolor="#CCCCCC" align="center">Cost</td> </tr> &

我对php非常陌生。我正在读一本书,书中有一个关于while循环的例子:

<html>
<body>
<table border="0" cellpadding="3">
<tr>
<td bgcolor="#CCCCCC" align="center">Distance</td>
<td bgcolor="#CCCCCC" align="center">Cost</td>
</tr>
<?

  $distance = 50;
  while ($distance <= 250) {
  echo "<tr>
    <td align=\"right\">".$distance."</td>
    <td align=\"right\">".($distance / 10)."</td>
    </tr>\n";

  $distance += 50;
}

?>
</table>
</body>
</html>

我不知道为什么没有打印
$distance
的值。你能帮我修一下吗?多谢各位

使用
启动代码块,然后尝试使用

<?php ?>

而不是

<? ?>

首先,在HTML上下文中(即,您正在编写HTML页面),php代码应以“
开头。使用模板样式更为清晰:

<html>
    <body>
        <table border="0" cellpadding="3">
            <tr>
                <td bgcolor="#CCCCCC" align="center">Distance</td>
                <td bgcolor="#CCCCCC" align="center">Cost</td>
            </tr>
            <?php for($distance = 50; $distance <= 250; $distance += 50): ?>
            <tr>
                <td align="right"><?php echo $distance ?></td>
                <td align="right"><?php echo $distance / 10 ?></td>
            </tr>
            <?php endfor ?>
        </table>
    </body>
</html>

距离
成本

这也与所见即所得编辑器(如dreamweaver)兼容。

主题外:使用CSS而不是内联属性,除非它们是
[class]
es或
[id]
s。PHP似乎不会被解释。是否启用了
mod_PHP
功能?如果是,我认为@Quentin是正确的:不要使用短标记!看看“相关的”“StackOverflow右侧的列。请重写你的问题的标题,因为它现在完全没有意义了。我过去常改
<html>
    <body>
        <table border="0" cellpadding="3">
            <tr>
                <td bgcolor="#CCCCCC" align="center">Distance</td>
                <td bgcolor="#CCCCCC" align="center">Cost</td>
            </tr>
            <?php for($distance = 50; $distance <= 250; $distance += 50): ?>
            <tr>
                <td align="right"><?php echo $distance ?></td>
                <td align="right"><?php echo $distance / 10 ?></td>
            </tr>
            <?php endfor ?>
        </table>
    </body>
</html>