AJAX - PHP event on listbox selection change
how can i get the query to run on any listbox selection change
if(isset($_POST['select'])){
$newselection=$_POST['select'];
$query = "SELECT count(*) FROM listings where description=" . $newselection. "";
$result = mysql_query($query);
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "Number of rows: {$row['count(*)']}";
}
}
currently it only works when submit button is pressed
i'm trying to avoid js..
* Also i have other queries running ajax
if(isset($_POST['button1'])){
$selection=$_POST['select'];
$queryres = "SELECT * FROM listings wh开发者_如何学JAVAere description=" . $selection. "";
$resultres = mysql_query($queryres);
while($rowres = mysql_fetch_array($resultres, MYSQL_ASSOC))
{
echo "<div style='position: absolute; left: 294px; top: 16px;' title='Site map' class='myclass'> <img src={$rowres['picture1']} alt=''/></div>" ;
echo "<div style='position: absolute; left: 294px; top: 116px;' class='myclass'>Number:{$rowres['number']} <br>Description : {$rowres['description']} <br><br></div>" ;
}
}
try this (it has nothing to do with php code, it's html)
<option onchange="this.submit();">
JS is the only alternative to the user clicking the submit button. Something like <select onchange="submit();">
would probably suffice.
精彩评论