是否可以通过数据库为函数填充变量?
从ajax请求通过函数调用后面的文件,以在我的索引页面上的div中显示。
文件如下:
$query = mysqli_query($con,"SELECT tagID, views FROM tbl_favorites");
$count = mysqli_num_rows($query);
if ($count == 0){
echo "Error to display!";
}
else{
$arrayViews = array();
while($results = mysqli_fetch_array($query))
{
$arrayViews[] = $results['views'];
}
}
$max = max($arrayViews);
rsort($arrayViews);
for ($i=0; $i<$count; $i++){
$favoriteQuery = mysqli_query($con,"SELECT tagID FROM tbl_favorites WHERE views = '".$arrayViews[$i]."'");
while ($favorite = mysqli_fetch_array($favoriteQuery)){
echo "<a class='favoriteKeyword' onclick='fetchResult(".$favorite['tagID'].", null);' href=><p id='key'>".$favorite['tagID']."</p></a>";
}
}
//close connection after query executes
mysqli_close($con);
&GT?;
这实际上是成功填充的,但是当在onClick = functionName
中使用该函数(从数据库中检索PHP值)时,它不起作用。为什么会这样?