简体   繁体   English

当我单击php时的while循环和条件

[英]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. 代码的问题是您在for循环中使用$i This is correct, but you need to use $i inside your code also. 这是正确的,但是您还需要在代码中使用$i 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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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