Solved

Interation on a while loop.

Posted on 2014-09-24
3
101 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses four methods for overlaying images in a container on a web page
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

820 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