Solved

Interation on a while loop.

Posted on 2014-09-24
3
103 Views
Last Modified: 2014-09-24
I can't see what's wrong with the following code.  It only does one iteration.
$_SESSION['Left_Bldg_Count'] displays "8".
$count display "0" on the one iteration.
$_SESSION['Left_Bldg'][$count]['SEQ'] show the correct data.

<?php
      $count = 0;
      echo "Left = ";
      echo $_SESSION['Left_Bldg_Count'];
      echo "<br>";
      while ($_SESSION['Left_Bldg_Count'] <= $count);
      {
            echo $count;
            echo "<br>";
            echo "Seq = ";
            echo $_SESSION['Left_Bldg'][$count]['SEQ'];
            echo "<br>";
            $count++;
      }
?>      
I know it's something stupid.
Glenn
0
Comment
Question by:breeze351
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 40342802
Change <= to >=.

Otherwise, it reads:

while(8 <= 0)
{
 ...
}
0
 
LVL 35

Accepted Solution

by:
gr8gonzo earned 500 total points
ID: 40342804
You could also do:

<?php
      echo "Left = ";
      echo $_SESSION['Left_Bldg_Count'];
      echo "<br>";

for($count = 0; $count <= $_SESSION['Left_Bldg_Count']; $count++)
{
            echo $count;
            echo "<br>";
            echo "Seq = ";
            echo $_SESSION['Left_Bldg'][$count]['SEQ'];
            echo "<br>";
}

Open in new window


That way, the for loop automatically declares and increments $count for you.
0
 

Author Closing Comment

by:breeze351
ID: 40342859
Thanks.  I've been staring at this all day.  Some time you need a new fresh of eyes.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

627 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question