Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/299.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中计算while循环内的乘法_Php_Mysql - Fatal编程技术网

在php中计算while循环内的乘法

在php中计算while循环内的乘法,php,mysql,Php,Mysql,可能重复: hi在这个编码中,如何从用户处获得一个输入值?我从数据库中获得的secound值 最后执行乘法严格来说,您的代码无法从用户那里获得值。要获得输入,您需要发送表单 假设你有一张表格 <form action="theNameOfTargetScript.php" method="post"> <input type="text" name="qty"/> <input type="submit"> </form> 一旦您提交了这样的表

可能重复:

hi在这个编码中,如何从用户处获得一个输入值?我从数据库中获得的secound值
最后执行乘法

严格来说,您的代码无法从用户那里获得值。要获得输入,您需要发送表单

假设你有一张表格

<form action="theNameOfTargetScript.php" method="post">
<input type="text" name="qty"/>
<input type="submit">
</form>
一旦您提交了这样的表单,您需要接收post值,然后将其与您需要的任何值相乘:

while($row = mysql_fetch_array($result))
  {
 echo "<tr>";
 echo "<td class='alt'>" . $row['id'] . "</td>";
 echo "<td>" . $row['item'] . "</td>";
echo "<td>" . $row['amount'] . "</td>";
$ss=$row['amount'];
$qty=$_POST['qty']; //The important bit. And for this to be meaningful, you should check if this value exists with isset($_POST['qty']);

echo "<td>" . $ss*$qty . "</td>";

echo "</tr>";


 }
此外,您使用的连接错误。由于本例中的HTML只是一个字符串,因此您可以按原样键入它们,而无需连接,如下所示:

echo '<td ><input type="checkbox"  name="status" value="" ></td>';
另外,您似乎没有对PHP做过任何研究,因为这是所有PHP网站的基本原则

编辑

自从你问起

是的,您可以在while循环中获得$\u POST值。 不,您不能在while循环中获取用户输入。

这种功能通常在C++命令行类应用程序中使用,但这不是PHP在HTTP上工作的方式。

echo '<td ><input type="checkbox"  name="status" value="" ></td>';