简体   繁体   中英

while loop and condition when i click php

When i click, i want 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 a last item. Before a last item, I have a second item which is not displayed.

How can i display item one by one ?

The problem with your code is you are using $i in your for loop. This is correct, but you need to use $i inside your code also. At the moment you are looping but doing the same execution every time. Here is a simple Example to help you.

for( $i = 0; $i < $count; $i++ ) {
  $x = $i;
  echo $x;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM