drisate Posted October 30, 2012 Share Posted October 30, 2012 Hey guys i did not sleep in 2 days and right now i am working on a triple combo box systeme and i am enable to concentrate my self to find an effective way of creating the javascript with my php loops ... This is the script i am using: http://www.javascriptkit.com/script/script2/triplecombo.shtml The part i am having a problem with is populating the array tree categories["startList"] = ["Wearing Apparel","Books"] categories["Wearing Apparel"] = ["Men","Women","Children"]; categories["Books"] = ["Biography","Fiction","Nonfiction"]; categories["Men"] = ["Shirts","Ties","Belts","Hats"]; categories["Women"] = ["Blouses","Skirts","Scarves", "Hats"]; categories["Children"] = ["Shorts", "Socks", "Coats", "Nightwear"]; categories["Biography"] = ["Contemporay","Historical","Other"]; categories["Fiction"] = ["Science Fiction","Romance", "Thrillers", "Crime"]; categories["Nonfiction"] = ["How-To","Travel","Cookbooks", "Old Churches"]; What i got so fare is: // Select pays $select_pays = mysql_query("SELECT * FROM pays order by nom_pays asc") or die(mysql_error()); while($pays = mysql_fetch_assoc($select_pays)){ $list_pays .= '"'.$pays['nom_pays'].'",'; // Select Province $select_province = mysql_query("SELECT * FROM province where id_pays='$pays[id_pays]' order by nom_province asc") or die(mysql_error()); while($province = mysql_fetch_assoc($select_province)){ echo 'categories["'.$province['nom_province'].'"] = ['; // Select ville $select_ville = mysql_query("SELECT * FROM ville WHERE id_province='$province[id_province]' order by nom_ville asc") or die(mysql_error()); while($ville = mysql_fetch_assoc($select_ville)){ $list_ville .= '"'.$ville['nom_ville'].'",'; } echo substr($list_ville, 0, -1).'];'."\n"; unset($list_ville); } } echo 'categories["startList"] = ['.substr($list_pays, 0, -1).'];'."\n"; Any help gething this back on tract would be appreciated. The above creates this output: categories["Alberta"] = ["Airdrie East","Airdrie West","Athabasca","Banff","Barrhead"]; categories["British Columbia"] = ["Abbotsford East","Abbotsford Southeast","Abbotsford Southwest","Abbotsford West","Atlin Region (Atlin)"]; categories["Manitoba"] = ["Brandon North","Brandon Region (Killarney)","Brandon Southeast","Brandon Southwest","Cartier"]; categories["New Brunswick"] = ["Allardville","Apohaqui","Baie-Sainte-Anne","Baker Brook","Balmoral"]; categories["Newfoundland and Labrador"] = ["Bonavista Peninsula (Bonavista)","Burin Peninsula (Marystown)","Carbonear","Central Labrador (Happy Valley-Goose Bay)","Central Newfoundland (Bishops Falls)"]; categories["Northwest Territory"] = ["Central Northwest Territories (Inuvik)","Southwestern Northwest Territories (Fort Liard)","Yellowknife"]; categories["Nova Scotia"] = ["Alder Point","Amherst","Antigonish","Bedford Northwest","Bedford Southeast"]; categories["Nunavut Territory"] = ["Central Nunavut (Cambridge Bay)","Inner Nunavut (Rankin Inlet)","Outer Nunavut (Iqaluit)"]; categories["Ontario"] = ["Acton","Ajax East","Ajax Northwest","Ajax Southwest","Algoma Southwest (Blind River)"]; categories["Prince Edward Island"] = ["Charlottetown North","Charlottetown Southeast Prince Edward Island Provincial Government","Charlottetown West","Kings and Queens counties (Elmira)","Montague"]; categories["Quebec"] = ["","Abitibi- T","Abitibi- T","Ahuntsic Central","Ahuntsic East"]; categories["Saskatchewan"] = ["Buena Vista","Central Saskatchewan (Humboldt)","Eastern Saskatchewan (Melfort)","Estevan","Lloydminster"]; categories["Yukon"] = ["Central Yukon (Dawson City)","Southeastern Yukon (Watson Lake)","Whitehorse"]; categories["startList"] = ["Canada"]; Quote Link to comment Share on other sites More sharing options...
drisate Posted October 30, 2012 Author Share Posted October 30, 2012 i was missing the the canada array containing all the provinces // Select pays $select_pays = mysql_query("SELECT * FROM pays order by nom_pays asc") or die(mysql_error()); while($pays = mysql_fetch_assoc($select_pays)){ $list_pays .= '"'.$pays['nom_pays'].'",'; echo 'categories["'.$pays['nom_pays'].'"] = ['; // Select Province $select_province = mysql_query("SELECT * FROM province where id_pays='$pays[id_pays]' order by nom_province asc") or die(mysql_error()); while($province = mysql_fetch_assoc($select_province)){ $province_list .= 'categories["'.$province['nom_province'].'"] = ['; $list_province .= '"'.$province['nom_province'].'",'; // Select ville $select_ville = mysql_query("SELECT * FROM ville WHERE id_province='$province[id_province]' order by nom_ville asc") or die(mysql_error()); while($ville = mysql_fetch_assoc($select_ville)){ $list_ville .= '"'.$ville['nom_ville'].'",'; } $province_list .= substr($list_ville, 0, -1).'];'."\n"; unset($list_ville); } echo substr($list_province, 0, -1).'];'."\n"; echo $province_list; } echo 'categories["startList"] = ['.substr($list_pays, 0, -1).'];'."\n"; If you know a cleaner way of doing the same thing let me know :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.