gpt4 book ai didi

php - PHP 和 MySQL 中的数学

转载 作者:行者123 更新时间:2023-11-30 01:23:27 25 4
gpt4 key购买 nike

我试图通过在文件中显示它们来使用数据库中的条目在 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 ();

最佳答案

这是您要打印的字符串:

"<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> ";

变量被替换为它们的值:

"<td> £ 

= 100;
= 25;
= 300;

= - - ;

print ();


</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);


echo "</td> ";

关于php - PHP 和 MySQL 中的数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18286619/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com