Results 1 to 5 of 5

Thread: [RESOLVED] Echoing conditional messages once

Hybrid View

  1. #1
    Addicted Member
    Join Date
    Sep 05
    Posts
    135

    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
    PowerPoster techgnome's Avatar
    Join Date
    May 02
    Posts
    21,636

    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 subscribe to all threads I participate, so there's no need to pm when there's an update.*
    *Proof positive that searching the forums does work: View Thread *
    * 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??? *
    * Use Offensive Programming, not Defensive Programming. * On Error Resume Next is error ignoring, not error handling(tm).
    "There is a major problem with your code, and VB wants to tell you what it is.. but you have decided to put your fingers in your ears and shout 'I'm not listening!'" - si_the_geek on using OERN

  3. #3
    Addicted Member
    Join Date
    Sep 05
    Posts
    135

    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
    Moderator
    Join Date
    Jan 05
    Location
    Sydney
    Posts
    13,612

    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
    Addicted Member
    Join Date
    Sep 05
    Posts
    135

    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
  •