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

        <?php
        $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>";
          }
         mysqli_free_result($result);
         mysqli_close($con);
        ?>


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
Posted
Updated 4-Aug-14 16:45pm
v3

1 solution

I think, You can use jquery ajax function.

http://api.jquery.com/jquery.ajax/[^]


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

Something like this (pseudocode)

JavaScript
jquery.onselect(){

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



selectquery.php

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



design.html


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

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