douxu0550 2015-11-19 11:13
浏览 25

我点击时循环和条件

I create a binary tree. I have a first question and when I click on 'yes', I want to see a second question which is left etc. But here, I see directly the last item.

When I click, I want to display a next item of my db like this:

for( $i = 0; $i < $count; $i++ ) {
    if(isset($_POST['yes'])){
        $select = $db->prepare('SELECT * FROM node where id=:id');
        $select->bindParam(':id', $current_id_left);
        $select->execute();
        $nodes = $select->fetch();

        $current_id_left = $nodes->id_left_node_children;
        $current_id_right = $nodes->id_right_node_children;
        $current_question = $nodes->questions;
    }

It works but the loop gives me the last item. Before the last item, I have a second item which is not displayed.

How can I display items one by one?

  • 写回答

1条回答 默认 最新

  • duangang3832 2015-11-19 11:44
    关注

    Use limit in mysql query. For first record use below query.

    SELECT * FROM node where id=$id LIMIT 0,1
    

    For next question change LIMIT 1,1, LIMIT 2,1 so an so..

    So update your start value of LIMIT by passing that value from next button thats it.

    评论

报告相同问题?