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?