Solved

Interation on a while loop.

Posted on 2014-09-24
3
96 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
  • 2
3 Comments
 
LVL 34

Expert Comment

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

Otherwise, it reads:

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

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

760 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now