當我們從數據庫中選擇一個值時,無法從daabase獲取contcon。請幫助我解決這個問題。基於下拉選擇從數據庫顯示數據使用Ajax?
drop.php
我有一個頁面drop.php其中包含下面的代碼。
<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script>
function showUser(id) {
//get the selected value
//make the ajax call
$.ajax({
url: 'getuser.php',
type: 'GET',
data: {option : id},
success: function(data) {
document.getElementById('txtHint').innerHTML=data;
}
});
}
</script>
</head>
<body>
<?php
include("database.php");
include("session.php");
$query = "SELECT * FROM invoicetable WHERE username='$_SESSION[username]'";
$result = mysql_query($query);
echo'<select name="users" onchange="showUser(this.value)">';
echo '<option value="">'.'--- Select ---'.'</option>';
while($row = mysql_fetch_assoc($result)) {
echo '<option value="'.$row['id'].'">' . $row['name'] . '</option>';
}
echo '</select>';?>
<br>
<div id="txtHint"><b></b></div>
</body>
</html>
getuser.php
<?php
include("database.php");
include("session.php");
$sql="SELECT address FROM invoicetable WHERE username='$_SESSION[username]'";
$result = mysql_query($sql);
echo "<table border='1' style='width:500'>
<tr>
<th>Address</th>
</tr>";
$row = mysql_fetch_array($result);
echo "<tr>";
echo "<td>" . $row['address'] . "</td>";
echo "</tr>";
echo "</table>";
?>
無法從daabase CONTNT時,我們會選擇database.Please值幫我對此。 在此先感謝
我有兩個字段與相同的username.username存儲在會話 – vyuser