我试图通过在文件中显示它们来使用我的数据库中的条目在 php 中进行简单的求和。除了总和之外,所有其他字段都完美显示
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$sql = 'SELECT make, id, model, bcosts, rcosts, value, id FROM referb';
mysql_select_db('ely');
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
die('Could not get data: ' . mysql_error());
}
while($row = mysql_fetch_assoc($retval))
{
echo "<tbody><tr class=\"odd\">
<td>{$row['make']} </td>".
"<td>{$row['model']} </td> ".
"<td>{$row['id']}</td> ".
"<td>{$row['bcosts']}</td> ".
"<td>{$row['value']}</td> ".
"<td>{$row['rcosts']}</td> ".
"<td> £
$first_number = {$row['bcosts']};
$second_number = {$row['rcosts']};
$third_number = {$row['value']};
$sum_total = $third_number - $second_number - $first_number;
print ($sum_total);
</td> ";
}
?>
我得到的输出是
£ = 100; = 25; = 300; = - - ; print ();