Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Interation on a while loop.

Posted on 2014-09-24
3
Medium Priority
?
104 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 2000 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

Industry Leaders: 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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
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.

722 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