* ************************* Bygarcon1986 ************ * ******************* display a three-dimensional array, save it for future use .! DOCTYPEhtmlhtmlheadheadbody? Phperror_reporting (E_ALL ^ E_NOTICE); $ connmysql_connect (localhost, charles, charles); mysql_se
/************************** By garcon1986 ********** * ********************/display a three-dimensional array, save it for future use. ! DOCTYPE htmlhtmlhead/headbody? Phperror_reporting (E_ALL ^ E_NOTICE); $ conn = mysql_connect (localhost, charles, charles); mysql_se
/************************** By garcon1986 ********** **********************/
Display a 3D array and save it for future use.
<! DOCTYPE html> <pead> </pead> <body> <? Phperror_reporting (E_ALL ^ E_NOTICE); $ conn = mysql_connect ("localhost", "charles", "charles"); mysql_select_db ("crm1204", $ conn ); // for better display of dump ($ vars, $ label = null, $ return = false) {if (ini_get ('html _ errors ')) {$ content = "<pre>/n"; if ($ label! = Null & $ label! = '') {$ Content. = "<B >{$ label }:</B>/n" ;}$ content. = htmlspecialchars (print_r ($ vars, true); $ content. = "/n </pre>/n";} else {$ content = "/n"; if ($ label! = Null & $ label! = '') {$ Content. = $ label. ":/n" ;}$ content. = print_r ($ vars, true ). "/n";} if ($ return) {return $ content;} echo $ content; return null;}/* Bad example $ query = "select * from entreprise "; $ result = mysql_query ($ query); while ($ row = mysql_fetch_assoc ($ result) {$ query2 = "select * from site where entreprise_id = $ row [entreprise_id]"; $ result2 = mysql_query ($ query2); $ a2 = array (); while ($ row2 = mysql_fetch_assoc ($ Result2) {$ query3 = "select * from salarie where site_id = $ row2 [site_id]"; $ result3 = mysql_query ($ query3 ); while ($ row3 = mysql_fetch_assoc ($ result3) {$ a3 [] = array ("text" => $ row3 [nom]);} if ($ a3 [site_id] = $ a2 [site_id]) {$ a2 [] = array ("text" => $ row2 [nom], 'Children '=> $ a3) ;}} if ($ a2 [entreprise_id] ==$ a1 [entreprise_id]) {$ a1 [] = array ("text" => $ row [id]. "". $ row [nom], 'Children '=> $ a2) ;}// print_r ($ a1 );// Echo json_encode ($ a1); dump ($ a1); */$ entreprise_q = mysql_query ("select * from entreprise "); $ site_q = mysql_query ("select * from site"); $ salarie_q = mysql_query ("select * from salarie"); $ result = array (); $ entreprise = array (); $ site = array (); $ salarie = array (); while ($ row = mysql_fetch_assoc ($ salarie_q) {if (! Is_array ($ salarie [$ row ['site _ id']) {$ salarie [$ row ['site _ id'] = array ();} $ salarie [$ row ['site _ id'] [$ row ['salarie _ id'] = $ row ['nom'];} while ($ row = mysql_fetch_assoc ($ site_q) {if (! Is_array ($ site [$ row ['Entreprise _ id']) {$ site [$ row ['Entreprise _ id'] = array ();} $ site [$ row ['Entreprise _ id'] [$ row ['site _ id'] = array ('name' => $ row ['nom'], 'salarie' => $ salarie [$ row ['site _ id']);} while ($ row = mysql_fetch_assoc ($ entreprise_q) {if (! Is_array ($ entreprise [$ row ['Entreprise _ id']) {$ entreprise [$ row ['Entreprise _ id'] = array ();} $ entreprise [$ row ['Entreprise _ id'] = array ('name' => $ row ['nom'], 'sites '=> $ site [$ row ['Entreprise _ id']);} // echo json_encode ($ entreprise); dump ($ entreprise);?> </Body> </ptml>