Problem retrieving full list of subcat

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
zed420
Forum Commoner
Posts: 32
Joined: Wed Jun 04, 2008 11:24 am

Problem retrieving full list of subcat

Post by zed420 »

Hi All
I'm trying to populate two dropdown box's, one is Category and by selecting one of them the second dropdown box is populated with it's Subcat, this code below works bit strangely it only gives me ONE Subcategory(client_site) can anyone please tell me why only one??? I've got about 10 site to each client.
thanks zed

Code: Select all

 
echo "
function fillCategory(){ 
 // this function is used to fill the category list on load
 
";
$q1=mysql_query("select client_id,client_name from client");
echo mysql_error();
while($nt1=mysql_fetch_array($q1)){
echo "addOption(document.emp_rec.cl_id, '$nt1[client_id]','$nt1[client_name]');";
}// end of while
?>
} // end of JS function
 
function SelectSite(){
 
removeAllOptions(document.emp_rec.site_id);
addOption(document.emp_rec.site_id, "", "Site Name", "");
 
<?
$q2=mysql_query("select site_id from client_site");
while($nt2=mysql_fetch_array($q2)){
echo "if(document.emp_rec.cl_id.value == '$nt2[site_id]'){";
$q3=mysql_query("select site_id,site_name from client_site where site_id='$nt2[site_id]'");
while($nt3=mysql_fetch_array($q3)){
echo "addOption(document.emp_rec.site_id,'$nt3[site_id]','$nt3[site_name]');";
} // end of while loop
echo "}"; // end of JS if condition
 
}
?>
}
function removeAllOptions(selectbox)
{
    var i;
    for(i=selectbox.options.length-1;i>=0;i--)
    {
        selectbox.remove(i);
    }
}
function addOption(selectbox, value, text)
{
    var optn = document.createElement("OPTION");
    optn.value = value;
    optn.text = text;
 
    selectbox.options.add(optn);
}
Post Reply