Click here to Skip to main content
12,756,447 members (31,633 online)
Rate this:
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.

$dbc = mysql_connect('*','*','*') 
     or die('Error connecting to MySQL server.'); 


$result = mysql_query("select * from tblRestaurants order by RestName ASC"); 

while ($nt= mysql_fetch_assoc($result))
    $arrData[] = $nt;

    echo json_encode($arrData);
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
<html xmlns="" xml:lang="en" lang="en"> 
    <script src="//" 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");
            $("#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");
            $("#Doggie").append('<option value="' + objRecord.RestID + '">' + objRecord.RestName + '</option>');

        <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 /> 
Posted 11-Jan-13 11:44am
Updated 12-Jan-13 5:59am

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170217.1 | Last Updated 12 Jan 2013
Copyright © CodeProject, 1999-2017
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