我想在SQL select $ query中传递JS变量+myarray.data[i].id+
的值,即我想要post_id=+myarray.data[i].id+
。
我该怎么做?我试过这个,但它不起作用。
ajaxsearchpagination.php文件
<script type="text/javascript">
function ajaxFunction(val)
{
var httpxml;
try
{
// Firefox, Opera 8.0+, Safari
httpxml=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
httpxml=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
httpxml=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
function stateChanged()
{
if(httpxml.readyState==4)
{
/////////////
var myarray = JSON.parse(httpxml.responseText);
//alert(httpxml.responseText);
// Before adding new we must remove previously loaded elements
for(j=document.getElementById('subject').length-1;j>=0;j--)
{
document.getElementById('subject').remove(j);
}
var str='';
var result='';
for (i=0;i<myarray.data.length;i++)
{
<?php
include ('starrating/dbConfig.php');
//Fetch rating deatails from database
$query = "SELECT *, FORMAT((total_points / rating_number),1) as average_rating FROM post_rating WHERE post_id = **'+myarray.data[i].id+'** AND status = 1";
$result = $db->query($query);
$ratingRow = $result->fetch_assoc();
?>
}
///////////
document.getElementById("subject").innerHTML= str;
document.getElementById("result").innerHTML= result ;
if(myarray.value.status1 != 'T'){
document.getElementById("msg").innerHTML="About " + myarray.value.no_records2 + " & " + myarray.value.no_records + " results " + " Message : "+ myarray.value.message;
}else{
document.getElementById("msg").innerHTML="About " + myarray.value.no_records2 + " & " + myarray.value.no_records + " results " ;
}
var endrecord=myarray.value.endrecord
document.getElementById("navigation").innerHTML= "<table width=700><tr><td width=350><input type=button id=\'back\' value=Prev onClick=\"ajaxFunction('bk'); return false\"></td><td width=350 align=right><input type=button value=Next id=\"fwd\" onClick=\"ajaxFunction(\'fw\'); return false\"></td></tr></tr> </table>";
myForm.st.value=endrecord;
if(myarray.value.end =="yes"){ document.getElementById("fwd").style.display='inline';
}else{document.getElementById("fwd").style.display='none';}
if(myarray.value.startrecord =="yes"){ document.getElementById("back").style.display='inline';
}else{document.getElementById("back").style.display='none';}
}
}
var url="search-backend.php";
var str=document.getElementById("keyword").value;
var myendrecord=myForm.st.value;
url=url+"?txt="+str;
url=url+"&endrecord="+myendrecord;
url=url+"&direction="+val;
url=url+"&sid="+Math.random();
//document.getElementById("txtHint").innerHTML=url
httpxml.onreadystatechange=stateChanged;
httpxml.open("GET",url,true);
httpxml.send(null);
document.getElementById("msg").innerHTML=":)...";
document.getElementById("msg").style.display='inline';
////////////////////////////////
}
</script>
</head>
<body>
<div id=msg style="position:absolute; width:300px; height:25px;
z-index:1; left: 400px; top: 0px;
border: 1px none #000000"></div>
<br><br><br><form name="myForm">
<input type=hidden name=st value=0>
<input type="text" onkeyup="ajaxFunction('');" name="keyword" id="keyword" list="subject" size=70/>
<datalist id="subject" >
</datalist>
<br><br>
<div class='t1' id='result'>
</div>
</form>
<div class='t1' id='navigation'>
</div>