如何在DIV上显示php的值?
数据库查询出来有3条记录$otherword = "SELECT*FROM word WHERE id !=".$id." ORDER BY id ASC LIMIT 3";
我把3条记录放在了数组里面
$wordarray = Array();//声明新数组
while($otherrow = $otherwordquery->fetch_assoc()){
//echo "<br>";
$otherenglish = $otherrow['english'];
//把3个字段的值放在数组里面;
array_push($wordarray,$otherenglish);
}
请问如何把$wordarray[0]-[2] 3条记录通过javascript分别放到下面上个div中?
<div id="englishdiv2" class="englishdiv"></div>
<div id="englishdiv3" class="englishdiv"></div>
<div id="englishdiv4" class="englishdiv"></div>
数据库查询出来有3条记录$otherword = "SELECT*FROM word WHERE id !=".$id." ORDER BY id ASC LIMIT 3";
我把3条记录放在了数组里面
$wordarray = Array();//声明新数组
while($otherrow = $otherwordquery->fetch_assoc()){
//echo "<br>";
$otherenglish = $otherrow['english'];
//把3个字段的值放在数组里面;
array_push($wordarray,$otherenglish);
}
请问如何把$wordarray[0]-[2] 3条记录通过javascript分别放到下面上个div中?
<div id="englishdiv2" class="englishdiv"></div>
<div id="englishdiv3" class="englishdiv"></div>
<div id="englishdiv4" class="englishdiv"></div>
如果DIV是写在PHP文件中的,可以这样来读取参数。<script>var value = "<?php echo $wordarray[0];?>";</script>
$result=mysql_query($otherword);
while($row=mysql_fetch_array($result)){
$arr[] = $otherrow['english'];
}
$cnt=count(arr);
$arr=array("cnt"=>$cnt,"English"=>$arr);
echo json_encode($arr);
//这是客户端取题的部分,取题的时候具体的数组ar的值还要根据你json传来的格式确定,我只给了你一个基本形式
<script type="text/JavaScript" src="js/jquery.js"></script>
<script type="text/JavaScript">
$(document).ready(function(){
$.ajax({
url: "a.php",
type: "get",
dataType: "html",
success:
function(json){
var cnt=json.cnt;
var ar=new Array();
for(var i=0;i<cnt;i++){
ar[i]=json.English[i];
}
$("#englishdiv2").append(ar["0"]);
$("#englishdiv3").append(ar["1"]);
$("#englishdiv4").append(ar["2"]);
}
})
})
</script>
$arr[] = $row['english'];