0

I am writing a loop that is building a table. With a mysql_num_row, I get how many persons (18), and I want tables with 6 persons max (so: $Peoples = (mysql_num_row($SQL_statement) /6;).

In the loop, I increment $Count: $Count = $Count + 1;

When I write:

Do{
  [code]
} while($Count == $Peoples);

The condition is not working: after 1 loop it exits from the loop. I printed $Count wich is 1, and $Peoples is 3.

Is there something to do with this? Thanks!

4 Answers 4

3

because 1 != 3. You need while($count != $Peoples)

Or better yet, while($count < $peoples)

Sign up to request clarification or add additional context in comments.

Comments

1

Do you mean to use

Do{
  [code]
} while($Count != $Peoples);

(note the inequality check).

The condition is not working: after 1 loop it exits from the loop. I printed $Count wich is 1, and $Peoples is 3.

== is the equality operator - it checks if both sides are equal.

Your PHP code is operating correctly - you are telling the code to exit when count is different to people. $Count wich is 1, and $Peoples is 3. meets that criteria. The code I've posted above will continue looping while count is not equal to people.

Comments

1

Maybe you want do { [code] } while($Count < $Peoples) or do { [code] } while($Count != $Peoples). What your program is doing right now is adding 1 to $Count and then checking the loop condition. Since $Count != $Peoples, the loop exits.

Comments

1

== is the equals comparison operator. Your count will never initially equal the number of people, so your loop doesn't loop (do-while loops always execute the initial code in the do section, regardless of whether or not the loop condition is met).

What you likely need is to use the < operator, as you're incrementing your count over the life of the loop.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.