我的代码有问题,原因是,当运行查询 un PHP FILE 时,它会从中检索所有记录SELECT * FROM material
,然后将其传递给 JS FILE 进行处理并以数组 json 格式存储所有记录,但显示此错误:
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result
resource in C:\AppServ\www\biblioteca\include\doLogin.php on line 31 []
_
带函数的 PHP 文件
.........
public function searchMat($tipoBusqueda,$terminoBuscar){
$query = " SELECT * FROM material ";
$result = mysql_query($query) or die (mysql_error());
$resultArray = mysql_fetch_assoc($result);
return $resultArray;
}
其他带有函数的 PHP 文件
$results = $db->searchMat($tipoBusqueda, $terminoBuscar);
$jsonSearchResults = array();
if ($results != false) {
while($row = mysql_fetch_assoc($results)) {
$jsonSearchResults = array (
'clavemat' => $row['cve_mat'],
'tipomat' => $row['tipo_mat'],
'titulomat' => $row['titulo_mat'],
'autormat' => $row['autor_mat'],
'editmat' => $row['edit_mat'],
'success' => 'success',
);
}
echo json_encode($jsonSearchResults);
}
编辑: