希望你做得好!
我有这个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),这意味着一旦我设定了这个金额,减去学生支付的学费。
所以我的重大问题是:
注意:未定义的索引:SUM(school_fee)
注意:我将SUM用于收集每个学生的所有相应付款,以便通过'fee_setting'减去,以便知道每个学生剩下多少钱。
请任何人都可以帮我删除这个笔记真的让我不开心。
答案 0 :(得分:1)
我不确定我是否正确理解了模糊描述的问题,它来自于您在PHP代码中执行$res['SUM(school_fee)']
时的情况?
您可能需要在SQL中进行别名(例如SELECT SUM(school_fee) AS sum_school_fees
),这样您之后就可以访问$res['sum_school_fees']
。
答案 1 :(得分:0)
我认为访问它的干净方法是为这些结果创建别名:
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']