求助:程序写了一些,卡死不会了程序目的:
1、公开捐赠信息
2、可按照收据单号、月份、捐赠者搜索数据库查询

数据库结构:
表:n
字段:
id = 收据单号
name = 捐赠者
date = 日期
cash = 现金
other = 物资
t = 备注求一个查询页面的源码,另外就是想有一个捐赠金额求和的,在页面下面就可以。不会写函数谢谢各位了!已有代码:(效果可看 http://weixiao.de/d/list.php)<?php       
$linkptr=mysql_pconnect("localhost","c","c");     
mysql_select_db("jiujiuwo_b",$linkptr) or die("无法选择数据库"); 
mysql_query("set names 'utf8'");
?> 
<head><meta http-equiv="content-type" content="text/html;charset=utf-8"> </head>
<table width=580 border=0 cellspacing=0 cellpadding=0 align=center>  
 <tr>   
  <td><font color=#0772b1 class=mid>      
 <b>捐赠信息列表</b> 
</font>    
 </td>
<tr>   
 <td colspan=2><hr size=1></td>  
 </tr></table> 
<table width=580 border=0  cellpadding=5 align=center>   
<tr>  
 <td align=center width=12% bgcolor=#dedede>收据编号</td>    
 <td align=center width=12% bgcolor=#dedede>捐赠者</td>
 <td align=center width=12% bgcolor=#dedede>日期</td>
 <td align=center width=12% bgcolor=#dedede>金额</td>
 <td align=center width=20% bgcolor=#dedede>物资</td>
 <td align=center width=17% bgcolor=#dedede>备注</td>
</tr><?php 
$result=mysql_query("select * FROM normal");  
while($array=mysql_fetch_array($result)){        //判断是否到达数据库的结尾 
echo"<tr> 
<td class=mid align=center width=12%>$array[id]</td> 
<td class=mid align=center width=12%>$array[name]</td> 
<td class=mid align=center width=12%>$array[date]</td> 
<td class=mid align=center width=12%>$array[cash]</td>
<td class=mid align=center width=20%>$array[other]</td> 
<td class=mid align=center width=17%>$array[t]</td> 
</tr>"; 

?></table>

解决方案 »

  1.   


    @jordan102就是希望高手帮忙,在后面加个  合计:XXX元(对CASH字段求和)另外,根据数据库结构帮忙写个能查询的页面,可按照收据单号、月份、捐赠者搜索数据库查询
      

  2.   

    select sum(cash) from normal1 求和 查询 你就根据输入的数据select一下
      

  3.   


    $num='';
    while($array=mysql_fetch_array($result)){ //判断是否到达数据库的结尾 
    echo"<tr> 
    <td class=mid align=center width=12%>$array[id]</td> 
    <td class=mid align=center width=12%>$array[name]</td> 
    <td class=mid align=center width=12%>$array[date]</td> 
    <td class=mid align=center width=12%>$array[cash]</td>
    <td class=mid align=center width=20%>$array[other]</td> 
    <td class=mid align=center width=17%>$array[t]</td> 
    </tr>"; 
    $num+=$array[cash];

    echo "<tr><td colspan='6' align='right'>$num</td></tr>";
    ?></table>
    //搜索的话你在页面写个表单,用post接收也很简单。
    $sql="select * from normal where id like '%$_POST[id]%' or name like '%$_POST[name]%' or date like '%$_POST[date]%'";   
    .........显示代码
      

  4.   


    谢谢啦~
    求和已经成功了。
    不过
    $sql="select * from normal where id like '%$_POST[id]%' or name like '%$_POST[name]%' or date like '%$_POST[date]%'";
    对应的HTML表单没学过…还真不会写。   
      

  5.   


    <form action="" method="post">
    请输入查询关键字:<input type="text" name="key">
    <input type="submit" name="submit" value="搜索">
    </form>//sql代码改为如下:
    $sql="select * from normal where id like '%$_POST[key]%' or name like '%$_POST[key]%' or date like '%$_POST[key]%'";