Javascript 使用AJAX、PHP和MySQL显示表数据
我想根据[plan]和[order_id]值显示一列数据[pin]。计划=9,订单号=0。希望使用ajax在不重新加载页面的情况下加载数据 这是我的HTML/脚本:Javascript 使用AJAX、PHP和MySQL显示表数据,javascript,php,jquery,mysql,ajax,Javascript,Php,Jquery,Mysql,Ajax,我想根据[plan]和[order_id]值显示一列数据[pin]。计划=9,订单号=0。希望使用ajax在不重新加载页面的情况下加载数据 这是我的HTML/脚本: <script> function showPins(str) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for I
<script>
function showPins(str) {
if (str == "") {
document.getElementById("txtHint").innerHTML = "";
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET","getPins.php?q="+str,true);
xmlhttp.send();
}
}
</script>
HTML:
<div align="center">
<h3>View PIN's</h3>
<form>
<select name="users" onchange="showPins(this.value)">
<option value="">Select Plan Type:</option>
<option value="1">Plan1</option>
<option value="2">Plan2</option>
<option value="3">Plan3</option>
</select>
</form>
<br/>
<div id="txtHint"></div>
</div>
功能显示引脚(str){
如果(str==“”){
document.getElementById(“txtHint”).innerHTML=“”;
返回;
}否则{
if(window.XMLHttpRequest){
//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}否则{
//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数(){
if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
open(“GET”、“getPins.php?q=“+str,true”);
xmlhttp.send();
}
}
HTML:
查看PIN
选择计划类型:
计划1
计划2
计划3
这是我的PHP文件(getPins.PHP):
阅读手册时,您的查询可能会出错
是的
WHERE (order_id=0 and plan=9 and id = '".$q."')
或
根据你的要求W3学校在这里受到不好的舆论;也许这只是职业上的嫉妒。不管怎么说,考虑到你使用了一个很好的现代API(MySQL),考虑使用准备好的语句。它不可能是最后一个。我试过这个查询,仍然没有显示。这是否与节名称和值有关?
$sql="SELECT * FROM attPins WHERE (order_id=0, plan=9 and id = '".$q."')";
WHERE (order_id=0 and plan=9 and id = '".$q."')
WHERE (order_id=0 OR plan=9 and id = '".$q."')