0

Please anybody can tell me what wrong with this code it showing this error---------> Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/ocwnewco/public_html/user/rejectedcase.php on line 62 the line 62 is showing this------->$ocwConnections = mysql_num_rows($result);

                            rejectedcase.php                
                            <?php
            require_once(ROOT_PATH.'DBconnect.php');
            ?>
            <?php
            /**
            *get count of Reject
            *
            **/
            function totalReject($zone,$Reject) {
            $result = mysql_query("SELECT * FROM ocwconnections WHERE ZoneID = '$zone' AND RejectID = '$Reject'");
            $ocwConnections = mysql_num_rows($result);
            return $ocwConnections;
            }
            $ocwConnections = mysql_fetch_array(mysql_query("SELECT * FROM ocwconnections"));
            $resultZone = mysql_query("SELECT * FROM  `connection_zone` WHERE `Zone` <> 'All' ");
            $resultReject = mysql_query("SELECT * FROM  `connection_Reject` WHERE `Reject` <> 'All'");
            ?>
            <?php
             ?>

            <table border="1">
              <tr>
                <th class="tbhed">Zone</th>
                <?php
            $Reject = array();
            while($connectioReject = mysql_fetch_array($resultReject)) {
            echo "<th class=tbhed>".$connectioReject['Reject']."</th>";
            $Reject[] = $connectioReject['RejectID'];
            }
            ?>
                <th class="tbhed">Total</th>
                <th class="tbhed">Percentage</th>
              </tr>
              <?php
            $arr = array();
            while($connectioZone = mysql_fetch_array($resultZone)) {
            ?>
              <tr>
                <th><?php echo $connectioZone['Zone']; ?></th>
                <?php
            foreach($Reject as $value){
            $arr[$connectioZone['ZoneID']][$value] = totalReject($connectioZone['ZoneID'],$value);
            echo "<td>".totalReject($connectioZone['ZoneID'],$value)."</td>";
            }
            ?>
                <td><?php
            $total = 0;
            foreach($arr[$connectioZone['ZoneID']] as $value ){
            $total = $value + $total;
            }
            echo $total;
            ?>
                </td>
                <td><?php
            foreach($arr[$connectioZone['ZoneID']] as $key => $val){
            if($key == 2){
            $complete = $val;
            }
            }
            @$per = $complete * 100 / $total;
            if(!$per){
            echo $per = 0;
            }
            else {
            echo $per;
            }
            ?>
                  % </td>
              </tr>
              <?php 
            }
            ?>
            </table>
MaheshDigarse
  • 17
  • 1
  • 6
  • Check your query by using or clause ex mysql_query("your query") or die ("! query"); this will let you know whether yor query is executing or not. – rohitr Nov 26 '13 at 07:08
  • See [this answer](http://stackoverflow.com/a/11674313/250259) for how to troubleshoot this. – John Conde Nov 29 '13 at 15:33

2 Answers2

0

Check $result before passing it to mysql_num_rows. You'll find that it's false because the query failed.

Check for result set whether its empty or not.

if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}

$row = mysql_num_rows($result);

Your new function would look like below one

function totalReject($zone,$Reject) {
     $result = mysql_query("SELECT * FROM ocwconnections WHERE ZoneID = '$zone' AND RejectID = '$Reject'");
     if($result === FALSE) {
         die(mysql_error()); // TODO: better error handling
      }

      $ocwConnections = mysql_num_rows($result);
      return $ocwConnections;
}
user2486495
  • 1,636
  • 11
  • 19
0
   The mysql_query is returning a boolean value meaning the sql query is probably failing and you're getting a false returned rather than a mysql resource.

    Have you checked your query?



try this 

$result = mysql_query("SELECT * FROM ocwconnections WHERE ZoneID = '".$zone."' AND RejectID = '".$Reject."'");