-1

at this moment the code listed below, as part of using it within 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}

but my results is 22, instead of 2, or 333 instead of 3 query results

what i'm trying to do is, to fetch the active services, based upon userid and to match with package x y q, and to display as total active services, based on the packages, as you can see i'am able to fetch the info, just the total is wrong, please point me to the right way to do it. thanks.

Svan
  • 23
  • 5
  • If you don't want to output something multiple times, then don't put it into a loop ... – CBroe Oct 04 '16 at 12:44

1 Answers1

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

change to

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

And stand outside the while line:

echo "$total";

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";
Se Kh
  • 37
  • 2
  • I did that, i even updated the code, and it does not work, example if i have 1 product, will show me 1, if i have 10 products, will show me 10x10 ex:101010101010101010, instead of just 10, any clue why? thanks – Svan Oct 04 '16 at 13:22