Hello all. So far everything is working correctly with my hierselect. The first select box stores all the states. The second select box is supposed to list the counties that are designated for the state that is selected. So far it's only listing one county and stops the listing. I did: echo $cname . '<br />'; and it echoed out the result set which lists more than one result. Bellow is my form snippet:
Code:
try {
$dbh = new PDO('mysql:host=localhost;dbname=disability_listing', 'foo', 'bar');
foreach ($dbh->query('SELECT id, state_name from state_listing ORDER BY `state_name` ASC') as $row) {
$stateID = $row['id'];
$name = $row['state_name'];
$states[$stateID] = $name;
foreach ($dbh->query("SELECT state_id, county_name from state_counties WHERE state_id = '$stateID'") as $row2) {
$sID = $row2['state_id'];
$cname = $row2['county_name'];
echo $cname . '<br />'; // echos all the results which is more than one!
$counties[$stateID][$sID] = $cname;
}
}
unset($dbh);
} catch (PDOException $e) {
die ($e->getMessage());
}
// add hierselect element
$select = $form->addElement('hierselect', 'county', 'State/County:');
$select->setOptions(array($states, $counties));
// add submit button
$form->addElement('submit', null, 'Submit');
I've been concentrating on this snippet: $counties[$stateID][$sID] = $cname; I think it has to do with that line. It seems as if the values aren't getting set into the array. What are your guys take on this? What should I change/add to get this to work properly?
-Thanks,
Rich