数据库是mssql的。在查询分析器里运行该语句没问题。但是。我在网站里用结果就是不一样。
select top 6 * from web_view where dnbh='$username' order by sfmonth desc
在mssql查询分析器里,运行,得到6条最新的结果, 但是,在页面上测试,就只能得到5条记录,少了最新那一条。
难道6 改为 7 ?
//connection to the database$dbhandle = mssql_connect($myserver, $myuser, $mypass) or die(连接不上数据库); //select a database to work with$selected = mssql_select_db($mydb, $dbhandle) or die(连接不上指定数据库); $username=trim($_post['username']);$password=trim($_post['pass']);//declare the sql statement that will query the database$query = select top 6 * from web_view where dnbh='$username' order by sfmonth desc ;//execute the sql query and return records$result = mssql_query($query) or die (查询数据失败: .mysql_error());$numrows = mssql_num_rows($result); $nrow=mssql_fetch_array($result);if ($password substr($nrow[3],-4)) {echo 输入有误,请正确输入用户名和密码。谢谢!;}else { if (empty($numrows)) echo 没有查到数据哦,请正确输入用户名和密码。谢谢!; else { //$nrow=mssql_fetch_array($result); echo 你好!电脑编号为; echo $username; echo ,; echo 户名; echo $nrow[2]; echo 月份 总费用
; while($row=mssql_fetch_array($result)) { echo; echo; echo $row[1]; echo ; echo; echo ($row[10]+$row[4]); echo ; echo
; } mssql_close($dbhandle); }}
回复讨论(解决方案) 第18行有 $nrow=mssql_fetch_array($result); 读取了第一条记录
所以就少了一条
38到48行的代码应改为
do{
echo
;
echo;
echo $row[1];
echo ;
echo;
echo ($row[10]+$row[4]);
echo ;
echo
;
}while($row=mssql_fetch_array($result));
即使用 do wuile 循环,而不是 while 循环
那个为了密码的判断的,我应该可以不用查询两次吧。
我再调整一下。
用两句sql来查算了。想不到什么好办法。