我收到此错误"警告:mysqli_fetch_assoc()预计参数1被mysqli_result,阵中给出"出的代码片断"searchcar.php"的
$modelmake = $_POST['model_make'];
$result = $db->select('car_information','*', 'Model_Make LIKE \'%$modelmake%\'');
while($row = mysqli_fetch_assoc($result))
{
echo 'Model'.$row['model_make'];
}
Run Code Online (Sandbox Code Playgroud)
这是来自"database.php"的select函数的代码片段
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;
}
Run Code Online (Sandbox Code Playgroud)
我想用这行"while($ row = mysqli_fetch_assoc($ result))"请指教!
你的select方法是返回一个array,而不是一个resource.这意味着mysqli_fetch_assoc抱怨是对的.
好消息是该select方法返回一个结果数组,这意味着您可以替换while($row = mysqli_fetch_assoc($result))为
foreach($result as $row)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9811 次 |
| 最近记录: |