【发布时间】:2014-06-14 22:17:21
【问题描述】:
我有一个简单的数据库,它是由页面中的表单填写的,在条目中一切正常。
我在数据库中有 2 个字段:all_students 和 current_students 由用户以我要计算的形式填写
诀窍是我只在输出页面中回显最新的数据库记录.. 只给我插入表单中的最新数据...
现在,我想创建一个新字段,自动为我提供缺席学生(所有 - 当前)
我已经尝试过,我读到我不能在数据库中创建一个新的计算字段,它不是一个 excel,所以我试图将这两个字段的计算结果回显到一个新值,即“缺课的学生”
你有什么建议?请帮忙,这是我的代码
<?php
$con=mysqli_connect("localhost","root","PasswordHere","DBnameHere");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT id, class, all_students, current_students FROM students ORDER BY id DESC LIMIT 1");
while($row = mysqli_fetch_array($result))
{
echo "Class: " . $row['class'] . "<br>";
echo "All students: " . $row['all_studnets'] . "<br>";
echo "Current students: " . $row['current_studnets'] . "<br>";
echo "Absent students: " . $row['all_studnets'] . - . $row['current_studnets'] . " <br>";
}
mysqli_close($con);
?>
【问题讨论】:
-
用减号删除句点
标签: php mysql database calculated-field