请有人告诉我此代码显示此错误有什么问题---------> 警告:mysql_num_rows()要求参数1为资源,在第62行的/home/ocwnewco/public_html/user/rejectedcase.php中给出布尔值 第62行显示-------> $ 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>
答案 0 :(得分:0)
检查 $ result ,然后再将其传递给 mysql_num_rows 。您会发现它是错误的,因为查询失败了。
检查结果集是否为空。
if($result === FALSE) {
die(mysql_error()); // TODO: better error handling
}
$row = mysql_num_rows($result);
您的新功能将如下所示
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;
}
答案 1 :(得分: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."'");