sql计算表里的数总和

<?php

<!doctype html>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

<link type="text/css" rel="stylesheet" href="../css/admin.css" />

<title>学生信息</title>

</head>

<div style="position:absolute;top: 140px ; left:330px; ">

<body>

<?PHP 

$sql1="select * from hourse $where order by hname desc $limit"; //此处加了降序

$res=mysql_query($sql1);

?>

<div>

</div>

<form action="lf_del.php" method=post> 

<table width="1000">

  <tr  width="100%">

    <h2 >公寓信息</h2>

  </tr>

  <tr>

    <th width="35">选项</th>

    <th width="12%">公寓名&nbsp;</th>

<th width="10%">居住性别&nbsp;</th>

    <th width="11%">房间数&nbsp;</th>

    <th width="11%">楼层数&nbsp;</th>

<th width="13%">应住人数&nbsp;</th>

    <th width="13%">实住人数&nbsp;</th>

    <th width="15%">操作</th>

  </tr>

  <?PHP 

while($rows=mysql_fetch_array($res)){

$sqladd2="update hourse set snumber='$totalnum2' where hid=$rows[0]";

mysql_query($sqladd2,$link);


$yingzhu=$rows[3]*$rows[4]*8;

$sqladd="update hourse set ynumber='$yingzhu' where hid=$rows[0]";

mysql_query($sqladd,$link);

?>

  <tr>

     <td width="6%"><input type=checkbox name=de[] value=<?php echo $rows[0];?>></td>

    <td width="14%"><?php echo $rows[1];?>&nbsp;</td>

<td width="11%"><?php echo $rows[2];?>&nbsp;</td>

    <td width="11%"><?php echo $rows[3];?>&nbsp;</td>

    <td width="11%"><?php echo $rows[4];?>&nbsp;</td>

    <td width="13%"><?php echo $yingzhu;?>&nbsp;</td>

    <td width="13%"><?php 

$sqlshizhu="select sum(rshi) from room where rhourse=$rows[hname]";

    $shizhu=mysql_query($sqlshizhu,$link);

    $rs=mysql_fetch_array($shizhu);

echo $rs["sum(rshi)"];?>&nbsp;</td>

    <td width="15%"> <a href="lf_update.php?id=<?php echo $rows[0];?>">修改</a> 

  </tr>

  <?php

}

?>

</table>

</form>

</body>

</div>

</html>

当倒数14行$rows[hname]数组里的内容是文字时计算不出实住人数为甚么?当内容为数字1233时就可以,注意是内容不是$rows[hname]里的hname。请问这个问题怎么解决呢,谢谢帮忙!!!!

慕仙203825
浏览 1442回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL