-
Feb 6th, 2012, 02:38 PM
#1
Thread Starter
Addicted Member
[RESOLVED] Echoing conditional messages once
Hi Folks,
I created this code below that I want to use in a for loop statement with an if statement. This might not be the best way to go about it, but it does work somehow. However, I have a problem with it. When I run the page, the code runs well only I have the output 'Proceed to checkout' in infinity. It keeps echoing proceed to checkout without stopping and I get a long page with the same text message. Sometime, it crashes.
Code:
<?php
$accountBalance = 560;
$cost = 123;
$pay = $accountBalance - $cost;
$msg = "You have insufficient money in your account.";
$accept = "Proceed to checkout";
$refuse = "Credit your account to continue.";
for (;;) {
if ($pay <= $accountBalance) {
echo $accept;
}
else
{
if ($pay > $accountBalance)
{
echo $msg . $refuse;
}
}
}
?>
Can someone help me out with any idea so that is echos 'Proceed to checkout' or any other output just once, please?
Thanks,
Menre
-
Feb 6th, 2012, 04:00 PM
#2
Re: Echoing conditional messages once
because you have it in a for loop with no end condition... as it is posted, I don't see a reason for the for loop anyways...
-tg
-
Feb 6th, 2012, 05:10 PM
#3
Thread Starter
Addicted Member
Re: Echoing conditional messages once
Thanks a lot. I have deleted the for loop and that solved the problem.
The right code is now
Code:
<?php
$accountBalance = 560;
$cost = 123;
$pay = $accountBalance - $cost;
$msg = "You have insufficient money in your account.";
$accept = "Proceed to checkout";
$refuse = "Credit your account to continue.";
if ($pay <= $accountBalance) {
echo $accept;
}
else {
if ($pay > $accountBalance)
{
echo $msg . $refuse;
}
}
?>
Once again, thank you.
-
Feb 6th, 2012, 07:48 PM
#4
Re: [RESOLVED] Echoing conditional messages once
Once you've got a satisfactory answer, you can help the rest of us out by marking this thread as resolved from the Thread Tools menu above the first post. I've done it for you this time.
-
Feb 7th, 2012, 06:47 AM
#5
Thread Starter
Addicted Member
Re: [RESOLVED] Echoing conditional messages once
I will always do that from now on. Thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|