我收到此錯誤「警告:mysqli_fetch_assoc()期望參數1爲mysqli_result,數組中給出的代碼片段爲 」searchcar.php「警告:mysqli_fetch_assoc()期望參數1爲mysqli_result,給出的數組爲
$modelmake = $_POST['model_make'];
$result = $db->select('car_information','*', 'Model_Make LIKE \'%$modelmake%\'');
while($row = mysqli_fetch_assoc($result))
{
echo 'Model'.$row['model_make'];
}
這裏是代碼片段來自 「database.php中的」 選擇功能
public function select(
$table,
$fields = '*',
$where = '1=1',
$order = '',
$limit = '',
$desc = false,
$limitBegin = 0,
$groupby = null,
$monitoring = false
) //monitoring is set to true to view the actual query
{
// $query ='SELECT ' . $fields . ' FROM ' . $table ;
$query = 'SELECT ' . $fields . ' FROM ' . $table . ' WHERE ' . $where;
if (!empty($groupby)) {
$query .= ' GROUP BY ' . $groupby;
}
if (!empty($order))
{
$query .= ' ORDER BY ' . $order;
if ($desc)
{
$query .= ' DESC';
}
}
if (!empty($limit))
{
$query .= ' LIMIT ' . $limitBegin . ', ' . $limit;
}
$result = $this->_sendQuery($query);
$resultArray = array();
while ($row = mysqli_fetch_assoc($result))
{
$resultArray[] = $row;
}
if ($monitoring)
{
// If monitoring is activated, echo the query
echo $query;
}
return $resultArray;
}
我想用這條線 「而($行= mysqli_fetch_assoc($結果))」 請指教!
什麼打印var_dump($結果)? –
您的'select()'回調已經使用'mysqli_fetch_assoc'收集了一個數組。你爲什麼認爲你需要再次調用它? – mario