如何使用此代码打印此结果我不认识自己我做错了什么可以帮助我
<?php
$brush_price = 5;
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Quantity</th>";
echo "<th>Price</th></tr>";
for ( $counter++ = 10; $counter <= 100; $counter += 10) {
echo "<tr><td>";
echo $counter;
echo "</td><td>";
echo $brush_price * $counter;
echo "</td></tr>";
}
echo "</table>";
?>
输出: -
Quantity Price
10 50
20 100
30 150
答案 0 :(得分:1)
我想你想要这样的东西:
for ( $counter = 10; $counter <= 100; $counter += 10)
答案 1 :(得分:0)
这里你去:相同的输出,用Javascript编写。把它放在你的html文件中。
var brush_price = 5;
document.write("<table border='1' align='center'>");
document.write("<tr><th>Quantity</th><th>Price</th></tr>");
for(var counter = 10; counter <= 100; counter += 10){
document.write("<tr><td>" + counter + "</td><td>" + (counter * brush_price) + "</td></tr>");
}
document.write("</table>");
答案 2 :(得分:0)
您的PHP代码(您输错了标签,它应该是PHP):
for ( $counter++ = 10; $counter <= 100; $counter += 10)
似乎你打算将$ counter变量初始化为某个初始值(0,也许?) $ counter ++表示$ counter = $ counter + 1,它是一个表达式。 你不能为表达式赋值,它会抛出无效的左侧赋值错误。
尝试更改以下代码...
for ( $counter = 10; $counter <= 100; $counter += 10)
Javascript等效:
var brush_price=5;
document.write('<table border="1" align="center"><tr><th>Quantity</th><th>Price</th></tr>');
for(var counter=0; counter <= 100; counter+=10){
document.write('<tr><td>'+counter+'</td></td>'+(counter*brush_price)+'</td></tr>');
}
document.write('</table>');
答案 3 :(得分:0)
希望这有帮助
$brush_price = 5;
echo "<table border=\"1\" align=\"center\">";
echo "<tr><th>Quantity</th>";
echo "<th>Price</th></tr>";
for ( $count = 1, $counter=10; $count <= 10; $count++,$counter += 10) {
echo "<tr><td>";
echo $count;
echo "</td><td>";
echo $brush_price * $counter;
echo "</td></tr>";
}
echo "</table>";