我在PHP,Javascript和MySQL中创建了一个下拉菜单。我通过Javascript/AJAX成功地与另一个PHP文件进行通信。在javascript中,我发送了一个ID,其中包含我在PHP文件中捕获的URL。在PHP文件中,我想检查ID的值,然后用它来检查它应该执行的查询。然后我想在每次翻阅时打印这些值。我觉得我在那里很孤单,但现在我很受伤。用Javascript/AJAX和PHP打印数值
的JavaScript:
function onRollOver(id)
{
if (window.XMLHttpRequest)
{
test=new XMLHttpRequest();
}
else
{
test=new ActiveXObject("Microsoft.XMLHTTP");
}
// document.getElementById('test').style.display="block";
if (id == 1)
{
console.log("This is one");
}
else if (id == 2)
{
console.log("this i stwo");
}
console.log("id = " + id);
test.open("GET","get_menu_id.php?id="+id,true);
test.send();
}
function onRollOut()
{
document.getElementById('test').style.display="none";
}
的PHP & HTML:
while($names = $get_category_names->fetch_object())
{
$li_data = "<li data-dir=";
//echo $li_data . $names->id . ">" . $names->name . "</li>";
echo "<a onmouseover='onRollOver($names->id);' onmouseout='onRollOut($names->id);' >" . "$names->name" . "</a>";
}
外部PHP文件:
<?php
require_once("../includes/constants.php");
require_once("../includes/connection.php");
require_once("functions.php");
$connect = connectDB();
//get the q parameter from URL
$id=$_GET["id"];
//lookup all hints from array if length of q>0
echo $id;
if ($id == 1)
{
$nintendo = $connect->query("SELECT DISTINCT (categorypath) FROM feeds WHERE category_id = 1");
while($names = $nintendo->fetch_object())
{
echo "<p>" . $names->categorypath . "</p>";
}
}
?>
让我们知道你收到了什么错误,如果有的话。 – castis 2013-03-18 23:31:21
我还没有。只是我不知道如何根据每个查询中的ID将这些值打印到我的网页上。 – marciano 2013-03-18 23:34:08