我正在尝试创建一个表并为其行赋值,但它无效。任何提示或建议将不胜感激:
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
th,td
{
padding:5px;
}
</style>
</head>
<?php
$subject = "ISIT307";
$location = "3.123";
$time = "4:30";
<table style="width:300px">
<tr>
<th>Subject</th>
<th>location</th>
<th>time</th>
</tr>
<tr>
<td>$subject</td>
<td>$location</td>
<td>$time</td>
</tr>
</table>
?>
</body>
</html>
答案 0 :(得分:2)
尝试以下方法:
<tr>
<td><?php echo $subject; ?></td>
<td><?php echo $location; ?></td>
<td><?php echo $time; ?></td>
</tr>
只要您想运行php代码,就需要使用<?php
和?>
。
答案 1 :(得分:0)
$ time =&#34; 4:30&#34 ;;后面有语法错误你不能直接通过php输出html,你可以调用echo或print。
<!DOCTYPE html>
<html>
<head>
<style>
table,th,td
{
border:1px solid black;
border-collapse:collapse;
}
th,td
{
padding:5px;
}
</style>
</head>
<?php
$subject = "ISIT307";
$location = "3.123";
$time = "4:30";
?>
<table style="width:300px">
<tr>
<th>Subject</th>
<th>location</th>
<th>time</th>
</tr>
<tr>
<td><?= $subject ?></td>
<td><?= $location ?></td>
<td><?= $time ?></td>
</tr>
</table>
</body>
</html>
答案 2 :(得分:0)
你的php中没有html,你的html中也没有php。
<?php
$subject = "ISIT307";
$location = "3.123";
$time = "4:30";
?>
<table style="width:300px">
<tr>
<th>Subject</th>
<th>location</th>
<th>time</th>
</tr>
<tr>
<td><?=$subject ?></td>
<td><?=$location ?></td>
<td><?=$time ?></td>
</tr>
</table>