Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript PHP Ajax MySQL
I am trying to populate a listbox with different buttons. The first one works fine, when I click on it the listbox populates. The problem is the other four options. I need to change the MySQL query to reflect the button so that the listbox populates proerly.
 
<?php
$dbc = mysql_connect('*','*','*') 
     or die('Error connecting to MySQL server.'); 
 
mysql_select_db('*'); 
 
$result = mysql_query("select * from tblRestaurants order by RestName ASC"); 
 
while ($nt= mysql_fetch_assoc($result))
    $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.RestID + '">' + objRecord.RestName + '</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> 
Posted 11-Jan-13 11:44am
Edited 12-Jan-13 5:59am
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Marcin Kozub 310
1 OriginalGriff 248
2 Sergey Alexandrovich Kryukov 215
3 Richard MacCutchan 202
4 Praneet Nadkar 197
0 OriginalGriff 8,048
1 Sergey Alexandrovich Kryukov 7,287
2 DamithSL 5,614
3 Manas Bhardwaj 4,986
4 Maciej Los 4,910


Advertise | Privacy | Mobile
Web04 | 2.8.1411023.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100