热搜:NVER node 开发 php

查询语句的问题

2024-09-11 22:45:01
查询语句的问题

数据库是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""; echo""; } mssql_close($dbhandle); }}


回复讨论(解决方案)

第18行有 $nRow=mssql_fetch_array($result); 读取了第一条记录
所以就少了一条
38到48行的代码应改为
    do{
        echo"

";
        echo"";
        echo"";
        echo"";
    }while($row=mssql_fetch_array($result));

即使用 do wuile 循环,而不是 while 循环

那个为了密码的判断的,我应该可以不用查询两次吧。

我再调整一下。

用两句sql来查算了。想不到什么好办法。

月份 总费用
"; echo $row[1]; echo""; echo ($row[10]+$row[4]); echo"
";
        echo $row[1];
        echo"
";
        echo ($row[10]+$row[4]);
        echo"