samerhannoun Posted August 9, 2011 Share Posted August 9, 2011 Hi guys ,, I want a help to create an array like this array('XXX'=>array(name=>' yyyy''VVV'=>array(name=>'uuuu'))I want this to implement nested check boxes so the values (XXX,VVV) just header not check box, so I make a field in the db table call selected as the following:IDname parent_idselectedbest wishes Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2011 Share Posted August 9, 2011 You need to use a recursive function to get the children of each box and add it to the array. e.g.: function get_checkboxes($parent = 0){ $retval = array(); $result = mysql_query('SELECT * FROM table WHERE parent_id=' . $parent); while ($row = mysql_fetch_assoc($result)) { $cur = array( 'name' => $row['name'], 'selected' => $row['selected'], 'children' => get_checkboxes($row['id']) ); $retval[] = $cur; } return $retval;} Link to comment Share on other sites More sharing options...
samerhannoun Posted August 9, 2011 Author Share Posted August 9, 2011 You need to use a recursive function to get the children of each box and add it to the array. e.g.:function get_checkboxes($parent = 0){ $retval = array(); $result = mysql_query('SELECT * FROM table WHERE parent_id=' . $parent); while ($row = mysql_fetch_assoc($result)) { $cur = array( 'name' => $row['name'], 'selected' => $row['selected'], 'children' => get_checkboxes($row['id']) ); $retval[] = $cur; } return $retval;} thx alot Justsomeguy!!!I got this point but how Can I now create the checkboxes ??Sorry seems stupid question??thx again Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2011 Share Posted August 9, 2011 You'll need another recursive function to loop through the array and print everything, or the function above can print instead of store in an array. Link to comment Share on other sites More sharing options...
samerhannoun Posted August 9, 2011 Author Share Posted August 9, 2011 You'll need another recursive function to loop through the array and print everything, or the function above can print instead of store in an array.best regards friend... thank you very much for your help and adviceBTW did you work on Zend FrameWork ? Link to comment Share on other sites More sharing options...
justsomeguy Posted August 9, 2011 Share Posted August 9, 2011 No, I didn't. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.