Results 1 to 5 of 5

Thread: [RESOLVED] Echoing conditional messages once

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    Resolved [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

  2. #2
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    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
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    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.

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Sep 2005
    Posts
    150

    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
  •  



Click Here to Expand Forum to Full Width