Solved

Interation on a while loop.

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

710 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