populate second combo box based on first

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

populate second combo box based on first

Post by cjkeane »

Hi.

I have a combo box populated by a query of all companynames in a table. I need a second combobox to find the related companybranch based on the selected companyname. i'm not sure how to go about doing it. Any hints? I 'do not' have a separate table for companybranch. the table data looks like this:

ID CompanyName CompanyBranch
1 ICBC Accounting
2 ICBC Claims
3 ICBC Autoplan insurance
4 WCB Billing
5 WCB Compensation

the first combox needs to display ICBC, WCB and when either of them is selected then the branch related to it is displayed in the second list.

COMBOBOX1: (this works)

Code: Select all

<?php  
$result=mysql_query("select CompanyName from principal group by CompanyName"); 
$options=""; 
while ($row=mysql_fetch_array($result)) { 
$companyname=$row["CompanyName"]; 
$options.="<OPTION VALUE=\"$companyname\">".$companyname.'</option>'; 
} 
?>
<select name="CompanyName" >
<option value="0"> < select > <?php echo $options ?> </option>
</select>
COMBOBOX2:
I'm not sure how to link them, but they must be linked by companyname, not an idnumber.

I'd appreciate the assistance.
Thanks.
internet-solution
Forum Contributor
Posts: 220
Joined: Thu May 27, 2010 6:27 am
Location: UK

Re: populate second combo box based on first

Post by internet-solution »

This has been discussed several times in this forum. Use the forum search function and you will get your answer.
Post Reply