我应该再问一下这个问题,因为在我纠正一些错误之后很难。
我的问题是,我未能查询2013年支付的约翰杰克逊的付款情况。
这假设当我插入name = John Jackson,class = grade 1和year = 2013时,查询假设在设置表中检查year = 2013的设置字段值并减去John从付款中支付的金额2013年的表。 示例:2013年的付款和设置表格中的(fee_setting-school_fee,boarding_setting-boading,exampaper_setting-exam_paper,lunch_setting-lunch)。
我有两张表“付款和设置” 付款表(仅用于存储付款信息)
id fname class school_fee boarding exam_paper lunch date year
1 John Jackson Grade one 100000 300000 30000 1000 2013-12-12 0000-00-00
设置表(用于存储每年实际支付的服务)
id boarding_setting exampaper_setting fee_setting lunch_setting year date
1 200000 30000 200000 180000 2013-12-18 NULL
300000 40000 300000 190000 2014-12-12 NULL
在设置表中,我把某项服务的实际支付一年,这样当学生支付例子(school_fee)时,设置表中的fee_setting字段将减去根据发布的年份支付表中支付的school_fee的数量。
这里的php脚本在(年)字段中加入两个表;
<?php include("../Connections/conn.php")?>
<?php
$fname="fname";
$date="date";
$class="class";
if(isset($_REQUEST['submit'])){
$fname = mysql_real_escape_string($_POST['fname']);
$date = mysql_real_escape_string($_POST['date']);
$class = mysql_real_escape_string($_POST['class']);
$sql2="SELECT SUM(boarding)as boarding,SUM(exam_paper)as
exam_paper,SUM(school_fee)as school_fee,SUM(lunch)as lunch,fname,class
,date,year FROM payment INNER JOIN
setting.year,payment.year from payment setting ON setting.year=payment.year
WHERE YEAR(date) = '$date' AND fname like '%".$fname."%' AND class like
'%".$class."%' AND year like '%".$date."%'";
$q=mysql_query($sql2);
}
else{
$sql="SELECT * FROM payment";
$q=mysql_query($sql);
}
?>
这是我用来输入搜索信息的表格
<form method="post">
<table width="500" border="0">
<tr>
<td>Student name</td>
<td><input type="text" name="fname" value="<?php echo $fname;?>" /></td>
<td>Class</td>
<td><input type="text" width="10" name="class" value="<?php echo $class;?>" /></td>
<td>Year</td>
<td><input type="number" name="year" value="<?php echo $date;?>" /></td>
<td><input type="submit" name="submit" value="Search" /></td>
这是echo脚本
<?php
while(!empty($q) and $res=mysql_fetch_array($q)){
?>
<tr>
<td width="15%"><?php echo $res['fname'];?></td>
<td width="8%"><?php echo $res['class'];?></td>
<td width="10%"><?php echo $res['boarding_setting']- $res['boarding'];?></td>
<td width="10%"><?php echo $res['exampaper_setting']- $res['exam_paper'];?></td>
<td width="8%"><?php echo $res['fee_setting']- $res['school_fee'];?></td>
<td width="10%"><?php echo $res['lunch_setting']- $res['lunch'];?></td>
<td width="10%" style="border-width:medium"><?php echo $res['date'];?></td>
</tr>
<?php }?>
我不知道哪里出错,直到它没有任何错误产生任何结果。