$result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");
while($row = mysql_fetch_array($result))
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
{
echo '<tr>';
echo '<td>'.$row['pcode'].'</td>';
echo '<td>'.$row['pdesc'].'</td>';
echo '<td>'.$row['date'].'</td>';
echo '<td>'.$row['time'].'</td>';
echo '<td><div align="center">'.$row['psold'].'</div></td>';
echo '<td><div align="center">'.$row['pleft'].'</div></td>';
echo '<td><div align="center">'.$row['pprice'].'</div></td>';
echo '<td><div align="center">'.$all.'</div></td>';
我想添加pleft和psold,$ all根本不起作用...我会用这段代码做什么?
答案 0 :(得分:1)
您遇到语法错误。您需要在括号内放置以下3行:
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
像:
while($row = mysql_fetch_array($result))
{
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
echo '<tr>';
....
答案 1 :(得分:1)
你必须在while语句之后添加while循环括号,如。
while($row = mysql_fetch_array($result))
{
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
...............
答案 2 :(得分:1)
将你的添加内容放入循环中,
因为在while循环中它不起作用,因为它没有得到正确的值
所以,试试这个
<?php
$result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");
while($row = mysql_fetch_array($result))
{
$all=$row['psold'] + $row['pleft'];
echo '<tr>';
echo '<td>'.$row['pcode'].'</td>';
echo '<td>'.$row['pdesc'].'</td>';
echo '<td>'.$row['date'].'</td>';
echo '<td>'.$row['time'].'</td>';
echo '<td><div align="center">'.$row['psold'].'</div></td>';
echo '<td><div align="center">'.$row['pleft'].'</div></td>';
echo '<td><div align="center">'.$row['pprice'].'</div></td>';
echo '<td><div align="center">'.$all.'</div></td>';
答案 3 :(得分:0)
试试这个。
$result = mysql_query("SELECT * FROM productlist1 order by pdesc ASC");
while($row = mysql_fetch_array($result))
{
$sold=$row['psold'];
$left=$row['pleft'];
$all=$left + $sold;
echo '<tr>';
echo '<td>'.$row['pcode'].'</td>';
echo '<td>'.$row['pdesc'].'</td>';
echo '<td>'.$row['date'].'</td>';
echo '<td>'.$row['time'].'</td>';
echo '<td><div align="center">'.$row['psold'].'</div></td>';
echo '<td><div align="center">'.$row['pleft'].'</div></td>';
echo '<td><div align="center">'.$row['pprice'].'</div></td>';
echo '<td><div align="center">'.$all.'</div></td>';
echo '</tr>';
}
答案 4 :(得分:-2)
尝试将值解析为整数,如
$all=intval($left)+intval($sold);
是的,还有一件事你错了!!