Jump to content

Recommended Posts

I have 5 buttons. When you click on one, it populates the listbox. The first one works, however I am at loss on how to get the other 4 to work. Any help is appreciated.

 

<?php
$dbc = mysql_connect('','',')
 or die('Error connecting to MySQL server.');
mysql_select_db('MyHead');
$place = mysql_query("select * from tblRestaurants order by RestName ASC");
$cuicine = mysql_query("select * from tblCuisines order by CuisineName ASC");
$city = mysql_query("select * from tblCities order by CityName ASC");
$state = mysql_query("select * from tblStates order by StateName ASC");
$zipcode = mysql_query("select * from tblLocations order by ZipCodeName ASC");
while ($nt= mysql_fetch_assoc($place))
   $arrData[] = $nt;
if(isset($_GET["ajax"]))
{
   echo json_encode($arrData);
   //die();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
   <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
   <script type="text/javascript">
function displayPlace()
{
   $.getJSON("index.php?ajax=true", function(data) {
    $.each(data, function(index, objRecord) {
	    var option=document.createElement("option");
	    option.value=objRecord.RestID;
	    option.text=objRecord.RestName;
	    $("#Doggie").append('<option value="' + objRecord.RestID + '">' + objRecord.RestName + '</option>');
    });
   });
}
function displayCuisine()
{
   $.getJSON("index.php?ajax=true", function(data) {
    $.each(data, function(index, objRecord) {
	    var option=document.createElement("option");
	    option.value=objRecord.CuisineID;
	    option.text=objRecord.CuisineName;
	    $("#Doggie").append('<option value="' + objRecord.CuisineID + '">' + objRecord.CuisineName + '</option>');
    });
   });
}
   </script>
   <title>SEARCH</title>
</head>
<body>
    <form>
    <button type="button" onclick="javascript:displayPlace();">Place</button>
    <button type="button" onclick="javascript:displayCuisine();">Cuisine</button>
    <button type="button" onclick="javascript:displayCity();">City</button>
    <button type="button" onclick="javascript:displayState();">State</button>
    <button type="button" onclick="javascript:displayZipCode();">Area</button>
    <br />

    <select name="Doggie" id="Doggie"></select>

    <br />
   </form>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/273041-changing-querys-for-dropdown-listbox/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.