我的代碼是繼IAM得到一個錯誤「警告:mysql_num_rows():提供的參數不是一個有效的MySQL結果資源......」幫我解決這個錯誤的mysql_num_rows
<?php
$type = $_REQUEST['type'];
#defauts
$maxRows_p = 10;
$pageNum_p = 0;
if (isset($_GET['pageNum_p'])) {
$pageNum_p = $_GET['pageNum_p'];
}
$startRow_p = $pageNum_p * $maxRows_p;
$limit = ' LIMIT '.$startRow_p.', '.$maxRows_p;
//BUILD Addition Search Conditions
if(isset($_REQUEST['district']) && ($_REQUEST['district'] != 'All'))
$search = ' district = '.$_REQUEST['district'];
if(isset($_REQUEST['city']) && ($_REQUEST['city'] != 'All'))
$search = ' city = '.$_REQUEST['city'];
$search= ' availibility = "0" ';
$searchStr = @implode(' and ',$search);
$sql = 'select * FROM properties WHERE type= "'.$type.'" and ';
$sql .= $searchStr;
## DEBUGi
//if($debugP) echo 'Zip Code Radius SQL<hr>'.$sql;
//Add column sorting
if($_REQUEST['sort'] != '')
$sort = ' order by added asc ';
else
$sort = $_REQUEST['sort'];
### DEBUG
if($debugP) echo 'Advanced Search Sql<hr>'.$sql;
$error['Results'] = 'Sorry no properties found.';
### Finished Building search sql and execting #####
$sql_with_limit = $sql . $sort . $limit;
if($debugP)
echo "<hr>Property Search with Limit SQL: $sql_with_limit";
//Perform search
$searchResults = mysql_query($sql.$sql_with_limit);
### BUILD OUTPUT ####
if (isset($_GET['totalRows_p'])) {
$totalRows_p = $_GET['totalRows_p'];
} else {
if($debugP)
echo "<hr>Property with out limit SQL: $sql $sort";
$all_p = mysql_query($sql.$sort);
$totalRows_p = mysql_num_rows($all_p); //$totalRows_p = mysql_num_rows($all_p);
if($debugP)
echo "<br>Result Rows $totalRows_p";
}
$totalPages_p = ceil($totalRows_p/$maxRows_p)-1;
if($debugP)
echo "<hr>Builting Query String for Limit: ";
//Build query string
foreach($_GET as $name => $value){
if($name != "pageNum_p")
$queryString_p .= "&$name=$value";
}
if($debugP)
echo $queryString_p;
?>
祈禱,你不會從[Bobby Tables](http://xkcd.com/327/)訪問。此代碼尖叫SQL注入。另外,在'mysql_query()'之後請教['mysql_error()'](http://php.net/manual/en/function.mysql-error.php)。 –
看起來像你試圖使用「$搜索」變量作爲數組...但它實際上是一個變量....所以內爆不應該工作,這可能會導致問題。將$ search替換爲$ search [] – YonoRan