Jump to content
xisto Community
moldboy

While Loop how to stop the timeout

Recommended Posts

I have written a piece of code that is to make a forum which contains a table consiting of two colums and a determind number of rows with a while loop, however when I test the page it goes and goes, and then returns an error stating that the maximum 30 second limit has been reached, I understand what that means I just don't know why it's looping forever:

	while ($weightnum > 0);	{	echo "<tr>";    echo   '<td><input name="wname"' . $appendval . ' type="text" id="wname" value="Catagorie Name"></td>';    echo   '<td><input name="wper"' . $appendval . ' type="text" id="wper" value="Percent Value"></td>';    echo "</tr>";	$appendval = $apendval + 1;	$weightnum = $weightnum - 1;	}

Also Am I appending a number to my variable correctly?

Share this post


Link to post
Share on other sites

Have you specified an initial value for $weightnum anywhere? Cos if you haven't, your counter doesn't know what it's s'posed to be counting down from. I would've thought it'd be easier to count up, but I don't s'pose it really matters.

Share this post


Link to post
Share on other sites

Yeah it pulls it from a forum page, I guess I could check to make sure I spelled it right. I also have a habbit of using the $ in my form variables, could check.

Also on the last two lines, could I not say:

 $appendval = ++;$weightnum = --;
??

Notice from BuffaloHELP:
Edited as per request.

Edited by BuffaloHELP (see edit history)

Share this post


Link to post
Share on other sites

Also on the last two lines, could I not say:

 $appendval = ++;$weightnum = --;

150865[/snapback]


Should be done like this:

$appendval++;$weightnum--;

That will increment or decrement the variable.

 

Also, I wrote a tutorial about this type of PHP scripting. It's on Xisto, the sister site to Xisto.

 

Here is the tutorial link:

Rapid HTML code generation using simple PHP

 

It might interest you. :P

 

vujsa

Share this post


Link to post
Share on other sites

Okay, I kinda have to vent here for just one moment, STUPID PHP AND IT'S STUPID LITTLE ISSUES.

So I found out what the problem was. Turns out that

while ($weightnum > 0);{echo "<tr>";   echo   '<td><input name="wname"' . $appendval . ' type="text" id="wname" value="Catagorie Name"></td>';   echo   '<td><input name="wper"' . $appendval . ' type="text" id="wper" value="Percent Value"></td>';   echo "</tr>";$appendval = $apendval + 1;$weightnum = $weightnum - 1;}
won't work however:
while ( $weightnum > 0 ){echo "<tr>";   echo   '<td><input name="wname"' . $appendval . ' type="text" id="wname" value="Catagorie Name"></td>';   echo   '<td><input name="wper"' . $appendval . ' type="text" id="wper" value="Percent Value"></td>';   echo "</tr>";$appendval = $apendval + 1;$weightnum = $weightnum - 1;}

That does... can you spot the diffrence? Look at the {.

Oh but thanks for the tutorial link, I just might have to use it. One rep point.

Share this post


Link to post
Share on other sites

Yeah, I've had the same problem. I've only recently been playing around with PHP - before that it was all ASP - and I'm always getting caught out by missing ; and { which are a lot harder to spot than a missing then or end if.

Share this post


Link to post
Share on other sites

Yeah the only other coding I've even kinda done is HTML, and I'll tell you, PHP may be easy but HTML certinaly is easier! It's just not so picky. :P

Share this post


Link to post
Share on other sites

I have written a piece of code that is to make a forum which contains a table consiting of two colums and a determind number of rows with a while loop, however when I test the page it goes and goes, and then returns an error stating that the maximum 30 second limit has been reached, I understand what that means I just don't know why it's looping forever:

	while ($weightnum > 0);	{	echo "<tr>";    echo   '<td><input name="wname"' . $appendval . ' type="text" id="wname" value="Catagorie Name"></td>';    echo   '<td><input name="wper"' . $appendval . ' type="text" id="wper" value="Percent Value"></td>';    echo "</tr>";	$appendval = $apendval + 1;	$weightnum = $weightnum - 1;	}

Also Am I appending a number to my variable correctly?

150853[/snapback]

I suggest using for() loops instead of while. In for(), it's easy... example is below:

 

for($i=0;$i<5;$i++){echo("testing $i<br>");}

Share this post


Link to post
Share on other sites

The reason HTML is easier is because it's not a real language. HTML is markup: that means it tells stuff what to look like. It's not considered a language because there are no variables or conditionals or stuff like that.

Share this post


Link to post
Share on other sites

The reason HTML is easier is because it's not a real language. HTML is markup: that means it tells stuff what to look like. It's not considered a language because there are no variables or conditionals or stuff like that.

152601[/snapback]


Yeah I know, that's why I wanted to learn an actual rograming language. Hence PHP

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.