似乎不能用php和html运行这段代码。我试过用html文件和php文件运行它,但还是不能运行。它需要看起来像一个餐馆的收据,我缺少什么?
<?php
$item1="Penne Alla Vodka w/ Chicken";
$q1=1;
$p1=15.95;
$item2="Baby Back Ribs Deluxe";
$q2=1;
$p2=20;
$item3="Vodka Martini";
$q3=1;
$p3=9;
$item4="Tiramisu";
$q4=1;
$p4=8.50;
$subtotal=($p1*$q1)+($p2*$q2)+($p3*$q3)+($p4*$q4);
$tax=0.08875*$subtotal;
$tip=0.2*$subtotal;
$finaltotal=$subtotal+$tax+$tip;
$host="Alia";
这里打破了php代码和html代码开始。
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td{
border: 1px solid black;
border-collapse: collapse;
}
th, td{
padding: 5px;
text-align: left:
}
</style>
</head>
<body>
<h2>
Invoice
</h2>
它主要是输出实际的代码本身,而不是当前的时间。
<p> Bar & Grill</p>
echo date("Y/m/d")."<br>";
echo date("h:i:sa");
echo $host;
<table style="width:50%">
<caption> Bill</caption>
<tr>
echo "<th>Qty</th>";
echo "<th>Desc</th>";
echo "<th>Amt</th>";
</tr>
<tr>
echo "<td>$q1</td>";
echo "<td>$item1</td>";
echo "<td>$p1</td>";
</tr>
<tr>
echo "<td>$q2</td>";
echo "<td>$item2</td>";
echo "<td>$p2</td>";
</tr>
<tr>
echo "<td>$q3</td>";
echo "<td>$item3</td>";
echo "<td>$p3</td>";
</tr>
<tr>
echo "<td>$q4</td>";
echo "<td>$item4</td>";
echo "<td>$p4</td>";
</tr>
echo</table>
echo "AMT" .<br>.$subtotal;
echo "Subtotal".<br>.$subtotal;
echo "Tax".<br>.$tax;
echo "Balance".<br>.$finaltotal;
</body>
</html>
?>
在这里,首先你的PHP代码必须放置在 <?php ?>
标签。其次,你在表中呼应变量的语法是错误的(串格式),这就是你没有得到他们的值的原因。
将你的代码改为
PHP代码
<?php
$item1="Penne Alla Vodka w/ Chicken";
$q1=1;
$p1=15.95;
$item2="Baby Back Ribs Deluxe";
$q2=1;
$p2=20;
$item3="Vodka Martini";
$q3=1;
$p3=9;
$item4="Tiramisu";
$q4=1;
$p4=8.50;
$subtotal=($p1*$q1)+($p2*$q2)+($p3*$q3)+($p4*$q4);
$tax=0.08875*$subtotal;
$tip=0.2*$subtotal;
$finaltotal=$subtotal+$tax+$tip;
$host="Alia";
?>
HTML代码
<!DOCTYPE html>
<html>
<head>
<style>
table, th, td{
border: 1px solid black;
border-collapse: collapse;
}
th, td{
padding: 5px;
text-align: left:
}
</style>
</head>
<body>
<h2>
Invoice
</h2>
<p> Bar & Grill</p>
echo date("Y/m/d")."<br>";
echo date("h:i:sa");
echo $host;
<table style="width:50%">
<caption> Bill</caption>
<tr>
echo "<th>".Qty."</th>";
echo "<th>".Desc."</th>";
echo "<th>".Amt."</th>";
</tr>
<tr>
echo "<td>".$q1."</td>";
echo "<td>".$item1."</td>";
echo "<td>".$p1."</td>";
</tr>
<tr>
echo "<td>".$q2."</td>";
echo "<td>".$item2."</td>";
echo "<td>".$p2."</td>";
</tr>
<tr>
echo "<td>".$q3."</td>";
echo "<td>".$item3."</td>";
echo "<td>".$p3."</td>";
</tr>
<tr>
echo "<td>".$q4."</td>";
echo "<td>".$item4."</td>";
echo "<td>".$p4."</td>";
</tr>
echo</table>
echo "AMT <br>".$subtotal;
echo "Subtotal <br>".$subtotal;
echo "Tax <br>".$tax;
echo "Balance <br>".$finaltotal;
</body>
</html>