0

I'm trying to create a form that has a couple drop downs. The first one populated by 'Customer Name' which is drawn from my MYSQL database. Once selected, the drop down menu below it populates to the available 'Customer Sites' associated to that 'Customer Name' from the database (over multiple rows in the table).

So I've been trying this through PHP & JS - i know very little JS so i'm cannibalizing a script i found online.

I'll strip down my code as to what i'm calling from the MYSQL database and where I need it to dynamically populate the JS. So far everything i'ved tried including trying to push the MYSQL info into a PHP array and then call that in JS encounters the problem of it will only show one site, not all associated to the company name. After days of looking up online and trying to macgyver it together, i've given in and decided to ask for help.

Summarized version of the MYSQL Table 'customersites'

siteCompany | siteName

ABC Customer        | Site1
123 Customer          | Site1
123 Customer          | Site2
ABC Customer        | Site2

PHP

   $sql = "SELECT siteName, siteCompany FROM customersites ORDER BY siteCompany";

Java - so where 'siteCompany' and 'siteName' is listed is where i need them to dynamically populate.

`$(window).load(function(){
siteCompany1=new Array('siteName1','siteName2','siteName3');
siteCompany2=new Array('siteName1','siteName2','siteName3');
....Rest of JS

I can get the company names dynamically populating, i just can't get all the sites in to the corresponding arrays. Can anyone advise how i can do this please?

coltras
  • 27
  • 4

1 Answers1

0

All You Need to do is simple steps you need to use Ajax first to Send Customer Name To server then Use PHP too Collect Data from Database about Site Name's then Use Somthing Like JSON to communicate with Javascript Witch You Used To send Request (AJAX Request) then You Will Get JSON Response in you Javascript And All You Have to do is to parse you json Response then add it too you Combobox you can learn about Ajax And JSON Here http://www.tutorialspoint.com/json/json_ajax_example.htm

then you can learn about make json in php here http://www.tutorialspoint.com/json/json_ajax_example.htm

You can Add to Your Dropdown add item to dropdown list in html using javascript

Community
  • 1
  • 1
Rome
  • 563
  • 1
  • 9
  • 25