Click here to Skip to main content
15,742,973 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
<select id="categoriesSelect" class="e1">
<option value="0">Please select a category you wish to view!</option>

        $con = mysqli_connect(,,,,);
        // Check connection
        if (mysqli_connect_errno())
           echo "<option>Failed to connect to MySQLi</option>" ;
         $result = mysqli_query($con,"SELECT * FROM Category");
         while($row = mysqli_fetch_array($result)) {
          echo "<option value='".$row['Category']."'>".$row['Category']."</option>";

So far this is all I have:

I need populate the business name (Bname) from the business table based upon the category selection from the first box. Can someone help me create a javascript function that will do this.

Note: The php portion needs to stay as close to its current format as possible, my server will not connect to the database unless that connection code is used.

The database scheme is as follows:
Category -Table
   Category -Column (Primary Key)

Business -Table
   Bname -Column (Primary Key)
   Category -Column Foreign Key referencing Category table

I need something similar to this :
Click Here for the picture
Updated 4-Aug-14 16:45pm

1 solution

I think, You can use jquery ajax function.[^]

If you select one in select box then fire onselect event..

Something like this (pseudocode)


jquery.ajax(call php file containing the select query)

send html selected value to php file

success:get data in an array 
 fill the second select box using jquery or js


 mysql select query to fill the box
return or echo php array


<select id=""> first select box</select>
<select>empty select </select>
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900