douning5041 2014-02-18 21:31
浏览 22

如何将我的php连接到mysql以获取ajax查询

I am trying to make this page sortable with a simple drop down. Right now there are only two different car makes in there and its not sorting those. I would like to be able to sort through make, model, and year, but need to figure this first part out first (right?).

Can somebody please help me out with this? Is there something wrong with my PHP code or my script or both?

<script>
function showCars(str)
{
if (str=="")
{
document.getElementById("showcars").innerHTML="";
return;
} 
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","getcars.php?q="+str,true);
 xmlhttp.send();
}
</script>

<form>
<select name="make" onchange="showCars(this.value)">
<option value="">Select a person:</option>
<option value="Ford">Ford</option>
<option value="Subaru">Subaru</option>
</select>
</form>
<br>
<div id="showcars">
<?php
$q = intval($_POST['q']);$con=mysqli_connect("mysql.database.com","user","password","table");
// Check connection
if (!$con)
 {
 die('Could not connect: ' . mysqli_error($con));
 }

 mysqli_select_db($con,"ford_man");
 $sql="SELECT * FROM make WHERE make = '".$q."'";

 $result = mysqli_query($con,$sql);

 while($row = mysqli_fetch_array($result))
 {

  echo '<span style="float: left; wdith="300px;">' . $row['pics']  . '</span>';
  echo '&nbsp; &nbsp; &nbsp; &nbsp;' . '<span style="font-size:28px;">' . $row['year'] .    '</span>';  echo "&nbsp;"; echo '<span style="font-size:28px;">' . $row['make'] . '</span>'; echo "&nbsp;"; echo '<span style="font-size:28px;">' . $row['model'] . '</span>';
  echo "<br>"; 
  echo '&nbsp; &nbsp; &nbsp; &nbsp;' . '<span style="font-size:32px;">' . $row['price'] . '</span>'; echo "&nbsp; &nbsp;"; echo '<span style="font-size: 26px;">' . $row['miles'] . '</span>'; echo "&nbsp;";  echo 'miles' ;
  echo "<br>";
  echo '<span style="width:800px; float:left;">' . $row['description'] . '</span>';
  echo "<br>";
  echo '<i> &nbsp; &nbsp;'; echo '<span style="font-size:12px;">' .  'Stock#' . '</span>';   echo '&nbsp;'; echo '<span style="font-size:12px;">' . $row['stock'] . '</span>'; echo'</i>';
  echo '<br>'; 
  echo '<br>';
  echo '<br>';
  echo '<a style="text-decoration: none; color: rgba(254,094,008,1.00);"   href="mailto:agustus64050@yahoo.com">' . 'Email Me About This Car' . '</a>';
  echo "<hr>";
 }
  mysqli_close($con);
 ?>
 </div>
  • 写回答

1条回答 默认 最新

  • douzhi0107 2014-02-18 21:37
    关注

    In your AJAX you're using GET whereas your php is looking in the POST superglobal

    评论

报告相同问题?

悬赏问题

  • ¥15 r语言神经网络自变量重要性分析
  • ¥15 基于双目测规则物体尺寸
  • ¥15 wegame打不开英雄联盟
  • ¥15 公司的电脑,win10系统自带远程协助,访问家里个人电脑,提示出现内部错误,各种常规的设置都已经尝试,感觉公司对此功能进行了限制(我们是集团公司)
  • ¥15 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢