我在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