mysql查询计数显示结果一次

时间:2016-10-04 12:41:45

标签: mysql whmcs

此时下面列出的代码,作为在whmcs中使用它的一部分

                                {php}
                        $cleansed_uid = (int) $_SESSION['uid'];
                        $query = "SELECT * FROM tblhosting WHERE userid=".mysql_escape_string($cleansed_uid)." AND (domainstatus='Active') AND (packageid='10' OR packageid='2' OR packageid='30' OR packageid='40' OR packageid='44' OR packageid='45' OR packageid='104' )";
                        $result = mysql_query($query);
                        $total = mysql_num_rows($result);
                        while ($data = mysql_fetch_array($result)) {
                        echo "$total";
                        }
                    {/php}

但我的结果是22,而不是2,或333而不是3 query results

我想要做的是,根据用户ID获取活动服务并与软件包xyq匹配,并根据软件包显示为总活动服务,如您所见;我能够获取信息,只是总数是错误的,请指出我正确的方法来做到这一点。 感谢。

1 个答案:

答案 0 :(得分:0)

while ($data = mysql_fetch_array($result)) {
                        $total = mysql_num_rows($result);

更改为

 $total = mysql_num_rows($result);
   while ($data = mysql_fetch_array($result)) {

站在外线:

echo "$total";

总数:

$cleansed_uid = (int) $_SESSION['uid'];
                        $query = "SELECT * FROM tblhosting WHERE userid=".mysql_escape_string($cleansed_uid)." AND (domainstatus='Active') AND (packageid='1' OR packageid='20' OR packageid='30' OR packageid='40' OR packageid='44' OR packageid='45' OR packageid='104' )";
                        $result = mysql_query($query);
                        $total = mysql_num_rows($result);
                        while ($data = mysql_fetch_array($result)) {
                        $id = $data["id"];
                        $domain = $data["dedicatedip"];
}
                            echo "$total";