chil_tablemain_table2
i have two tables which i attached. user can add N level question answers. i am using CI.

i am using this code for generating ul li. and my array which fetch result set is like this.... but not working ...
for working ul li function i have to pass this array. so how to convert
$tree = array('A', 'B', 'C' => array('CA', 'CB'), 'D');

Array
(
    [0] => Array
        (
            [pkQMainAnsId] => 5
            [parent_id] => 0
            [QuestionAnswerText] => This is i am gussing my favor
            [AnswerOption] => Sooby
        )

    [1] => Array
        (
            [pkQMainAnsId] => 6
            [parent_id] => 0
            [QuestionAnswerText] => This is i am gussing my favor
            [AnswerOption] => dooby 
        )

    [2] => Array
        (
            [pkQMainAnsId] => 7
            [parent_id] => 0
            [QuestionAnswerText] => This is i am gussing my favor
            [AnswerOption] => zoooby
        )

    [3] => Array
        (
            [pkQMainAnsId] => 8
            [parent_id] => 0
            [QuestionAnswerText] => This my favo hero
            [AnswerOption] => Davidw
        )

    [4] => Array
        (
            [pkQMainAnsId] => 9
            [parent_id] => 0
            [QuestionAnswerText] => This my favo hero
            [AnswerOption] => shavida
        )

)




public function olLiTree($tree) {
        $out = '<ul id="tree" class="treeview">';

        foreach($tree as $key => $value) {
            $out.= '<li>';

            if (is_array($value)) {
                $out.= $key . $this->olLiTree($value);
            } else {
                $out.= $value;
            }

            $out.= '</li>';
        }

        $out.= '</ul>';

        return $out;
    }

can't read what the top table is called but something like this:

$Q = "SELECT * FROM `toptable`";
$R = mysql_query($Q);
if($R !== false){
    $ularray = array();
    while($row = mysql_fetch_assoc($R)){
        $ularray[$row['FKGMainId']][] = $row;
    }
}else{
    die('no data: '.mysql_error());
}

foreach($ularray as $k=>$v){
    echo "{$k}<ul>\r\n";
    foreach($v as $li){
        echo "<li>{$li['QuestionAnswerText']}</li>\r\n";
    }
    echo "</ul>\r\n";
}

note the php vars will be case sensitive to the field names in mysql, unless you specify names in the select.

If you want the bottom tables data in the same query do a left join:

$Q = "SELECT * FROM `toptable` a LEFT JOIN `bottable` b ON a.FKGMainId = b.PKGMainId";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.