Tell me more ×
Code Review Stack Exchange is a question and answer site for peer programmer code reviews. It's 100% free, no registration required.

I'm working on a CMS, currently on being able to create static pages, manage menus etc. so.. I have This function that reads from the DB and finds all the static pages, and their position in the menu. I want to know what Do you think.

function update_menu(&$pdo, $filepath){
$qry = "SELECT * FROM pages WHERE top = 1";
$exec = $pdo->query($qry);
$string = "<ul>";
while($row=$exec->fetch(PDO::FETCH_ASSOC)){
    $string.= "<li><a href='?page=".$row['id']."'>".$row['title']."</a>";
        $qry = "SELECT * FROM pages WHERE parent = ?";
        $child_ex = $pdo->prepare($qry);
        $child_ex->bindValue(1, $row['id'], PDO::PARAM_INT);
        if($child_ex->execute()){
            $i=0;
            while($child=$child_ex->fetch(PDO::FETCH_ASSOC)){
                if($i==0){
                    $string.="<ul>";
                }
                $string.="<li><a href='?page=".$child['id']."'>".$child['title']."</a>";
                $i++;
            }
            if($i != 0)
                $string.="</ul>";
        }
    $string.="</li>";
}
$string.="</ul>";
file_put_contents($filepath, $string);

};

Output html:

<ul><li><a href='?page=1'>Page1</a><ul><li><a href='?page=4'>append1</a><li><a href='?page=5'>append2</a></ul></li><li><a href='?page=2'>page2</a><ul><li><a href='?page=6'>append1b</a></ul></li><li><a href='?page=3'>page3</a></li></ul>

SampleOutput

share|improve this question
What is the purpose of this CMS? After all, there is a lot of PHP based CMS'es already, so why reinvent another? – Michael Zedeler Jun 13 at 22:25
there's not propose, I like to do my own stuff plus its a good way of learning and gaining experience (Im a Cs student) – Carlos Arturo Alaniz Jun 13 at 22:40

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.