希望你一切都好!
我有这个php脚本,可让用户搜索数据库中学生的待付款项,
$fname="fname";
$date="date";
$class="class";
$database=("mcl");
mysql_connect("localhost","root","mcl");
@mysql_select_db(mcl) or die( "Unable to select database");
if(isset($_REQUEST['submit'])){
$fname=$_POST['fname'];
$date=$_POST['date'];
$class=$_POST['class'];
$sql="SELECT
SUM(school_fee),SUM(trans_fee),SUM(edutrip_fee),SUM(reg_fee),
SUM(food_fee),SUM(stationery_fee),SUM(uniform_fee),idnumber,
edutrip_setting,stationery_setting,food_setting,uniform_setting,
register_setting,trans_setting,fee_setting,SUM(sport_uniform),
sport_setting,fname,class,date FROM payment_one
WHERE fname like '%".$fname."%' AND class like '%".$class."%' AND date
like '%".$date."%'";
<?php
while($res=mysql_fetch_array($q)){
?>
<tr>
<td width="100"><?php echo $res['fname'];?></td>
<td width="200"><?php echo $res['fee_setting']- $res['SUM(school_fee)'];?></td>
<td width="100"><?php echo $res['trans_setting']- $res['SUM(trans_fee)'];?></td>
<td width="200"><?php echo $res['stationery_setting']-
$res['SUM(stationery_fee)'];?></td>
<td width="200"><?php echo $res['register_setting']- $res['SUM(reg_fee)'];?></td>
<td width="10"><?php echo $res['food_setting']- $res['SUM(food_fee)'];?></td>
<td width="10"><?php echo $res['uniform_setting']- $res['SUM(uniform_fee)'];?></td>
<td width="10"><?php echo $res['edutrip_setting']-
$res['SUM(edutrip_fee)'];?>
</td>
<td width="10"><?php echo $res['sport_setting']- $res['SUM(sport_uniform)'];?></td>
<td width="30"><?php echo $res['class'];?></td>
<td width="280" style="border-width:medium"><?php echo $res['date'];?></td>
</tr>
<?php }?>
这是一张桌子
$num="create table payment_one
(id int primary key NOT NULL AUTO_INCREMENT,
fk_id varchar (10) NULL,
idnumber varchar (10) NULL,
fname varchar (50) NOT NULL,
class varchar (15) NOT NULL,
school_fee FLOAT(8,2),
trans_fee FLOAT(8,2),
stationery_fee FLOAT(8,2),
reg_fee FLOAT(8,2),
food_fee FLOAT(8,2),
uniform_fee FLOAT(8,2),
edutrip_fee FLOAT(8,2),
edutrip_name varchar (20),
fee_setting FLOAT(8,2) NOT NULL,
uniform_setting FLOAT(8,2) NOT NULL,
register_setting FLOAT(8,2) NOT NULL,
food_setting FLOAT(8,2),
edutrip_setting FLOAT(8,2) NOT NULL,
stationery_setting FLOAT(8,2),
trans_setting FLOAT(8,2) NOT NULL,
sport_uniform FLOAT(8,2),
sport_setting FLOAT(8,2) NOT NULL,
date date NULL)";
一旦您看起来合适,您可能会在“ payment_one”表中找到设置字段,该字段中包含学生应该支付的实际金额,例如(fee_setting为100000),这意味着一旦我设置了此金额,便会减去该金额学生支付的school_fee费用。
所以我最大的问题是这样的:
注意:未定义的索引:SUM(school_fee)
注意:我将SUM汇总为收集每个学生各自的所有付款,以便可以通过“ fee_setting”减去-以了解每个学生还剩下多少。
请任何人都可以帮助我删除此注释,这确实使我不高兴。
最佳答案
我认为干净的访问方式是为这些结果创建别名:
SELECT
SUM(school_fee) AS school_fee,
SUM(trans_fee) AS trans_fee,
SUM(edutrip_fee) AS edutrip_fee,
SUM(reg_fee) AS reg_fee,
SUM(food_fee) AS food_fee,
SUM(stationery_fee) AS stationary_fee,
SUM(uniform_fee) AS uniform_fee, ...
然后以以下方式访问它们:
$res['school_fee']