Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 21 of 21
  1. #16
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    Hello All!

    Doing more research and reading more on this issue, I found that using a more comprehensive if and else statement with more logics built into the statements worked best for my need. Below, please review what I have now. It works as I intend it to work. However, if there are any constructive comments on the approach, I would appreciate reading it. Thanks!

    PHP Code:
    //the variables in the here are provided from elsewhere in the complete code.
    $options = array();
    $options[0]["Open Play "] = "Your fee for today is <font color='white'>$".$open_play.".00</font> <br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /> <font color='white' size='3'>Thank you" .$firstname.", and have a great work-out!</font>";
    $options[0]["Robotic Training "] = "Your fee for today is <font color='white'>$".$robotic_play.".00 per 30 minute block</font> <br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Coaching Session "] = "<font color='red'>Please see Club Management for today's  coaching fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Robotic Training "] = "For these selections, please pay a <font color='white'>$".$play_combo.".00 deposit</font>, the balance after playing!<br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's  fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play "] ="Your fee for today is <font color='white'>$".$open_play.".00</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /> <font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Robotic Training "] = "Your fee for today is <font color='white'>$".$robotic_play.".00 per 30 minute block</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Coaching Session "] = "<font color='red'>Please see Club Management for today's  coaching fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Robotic Training "] = "Your Starting fee for today is <font color='white'>$".$play_combo.".00</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's  fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    //In my complete code; $play_envir variable could be any of the following:"Open Play, Robotic Training, Coaching Session "
    if($plyr_crdit_raw >'0'  && $plyr_crdit_raw $play_combo )
    {
      
    //if credit exists, payment will be deducted from credit
      
    if(isset($options[1][$play_envir]))
      {
        echo 
    $options[1][$play_envir];
      }
      else
      {
        echo 
    "Sorry we don't have that option (credit)";
      }
    }
    // else we need a payment amount indicated
    else
    {
      if(isset(
    $options[0][$play_envir]))
      {
        echo 
    $options[0][$play_envir];
      }
      else
      {
        echo 
    "Sorry we don't have that option (no Credit)";
      } 
    Last edited by mbarandao; 03-28-2013 at 01:41 PM.

  2. #17
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    be carefull of the spaces in your array key names

    $options[0]["Open Play "]

    after Play and before the "
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month

  3. #18
    Regular Coder
    Join Date
    Nov 2010
    Location
    Washington DC
    Posts
    341
    Thanks
    22
    Thanked 1 Time in 1 Post
    Arcticwarrio,

    Is there a way to get around the space issue inside array. I need the phrase "Open Play" to be represented in like manner. "OpenPlay" or "Open_Play" would not mean the same as "Open Play" for my purpose.

    Can you suggest a work around without using trim().

    Best!

  4. #19
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,343
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by mbarandao View Post
    Is there a way to get around the space issue inside array. I need the phrase "Open Play" to be represented in like manner. "OpenPlay" or "Open_Play" would not mean the same as "Open Play" for my purpose.
    That is not what Arctic was saying. Look again, Arctic was pointing out that you have a space AFTER the word Play. Thats why he has made the y and the " red. He was not talking about the space in between the words.
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  5. #20
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,343
    Thanks
    60
    Thanked 527 Times in 514 Posts
    Blog Entries
    4
    Quote Originally Posted by mbarandao View Post
    PHP Code:
    //the variables in the here are provided from elsewhere in the complete code.
    $options = array();
    $options[0]["Open Play "] = "Your fee for today is <font color='white'>$".$open_play.".00</font> <br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /> <font color='white' size='3'>Thank you" .$firstname.", and have a great work-out!</font>";
    $options[0]["Robotic Training "] = "Your fee for today is <font color='white'>$".$robotic_play.".00 per 30 minute block</font> <br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Coaching Session "] = "<font color='red'>Please see Club Management for today's  coaching fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Robotic Training "] = "For these selections, please pay a <font color='white'>$".$play_combo.".00 deposit</font>, the balance after playing!<br /><font color='red' size='8'><img border='0' src='images/form-flashing-arrow.gif' width='65' height='36'>Please Pay First!</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[0]["Open Play and Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's  fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play "] ="Your fee for today is <font color='white'>$".$open_play.".00</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /> <font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Robotic Training "] = "Your fee for today is <font color='white'>$".$robotic_play.".00 per 30 minute block</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Coaching Session "] = "<font color='red'>Please see Club Management for today's  coaching fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Robotic Training "] = "Your Starting fee for today is <font color='white'>$".$play_combo.".00</font> <br /><img border='0' src='images/form-flashing-arrow.gif' width='45' height='26'><span style='background-color:white'><font color='green' size='5'>Payment Will be Deducted from your Credit on file!</font></span><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    $options[1]["Open Play and Robotic Training and Coaching Session "] = "<font color='red'>Please see Club Management for today's  fee</font><br /><font color='white' size='3'>Thank you ".$firstname.", and have a great work-out!</font>";
    //In my complete code; $play_envir variable could be any of the following:"Open Play, Robotic Training, Coaching Session " 
    Again, you need to look at your quotes as I have pointed out time and time again now.

    You're using double quoted strings, terminating them and then concat'ing a variable before jumping back into double quoted strings. To make matters worse you're then using single quotes for your html values EG:

    PHP Code:
    $String "<font color='white' size='3'>Thank you" .$firstname.", and have a great work-out!</font>"
    Would be far better as:
    PHP Code:
    //Single quotes
    $String '<font color="white" size="3">Thank you' .$firstname.', and have a great work-out!</font>';

    //OR
    //Tell php to ignore " inside a string by using \"
    $String "<font color=\"white\" size=\"3\">Thank you $firstname, and have a great work-out!</font>"
    HTML is supposed to use double quotes. I've never found a browser that does not read single quotes but thats besides the point - you should be outputting double quotes in your html (as far as I know anyway - i think this is part of the official html standard).

    If you're going to add a value onto a string, then use single quotes for the hard coded string before adding the variable onto it. Otherwise just put it all in double quotes including the variable. If you put hard coded text in your double quotes without any variables you are wasting CPU power. If you don't start optimizing your scripts (including database sql) your scripts will eventually crash a server and you'll get your account suspended by your host.

    You really should start taking notice of advice about optimising things any and every way possible
    See my new CodingForums Blog: http://www.codingforums.com/blogs/tangoforce/

    Many useful explanations and tips including: Cannot modify headers - already sent, The IE if (isset($_POST['submit'])) bug explained, unexpected T_CONSTANT_ENCAPSED_STRING, debugging tips and much more!

  6. #21
    Regular Coder Arcticwarrio's Avatar
    Join Date
    May 2012
    Location
    UK
    Posts
    721
    Thanks
    20
    Thanked 84 Times in 84 Posts
    you could take all the spaces out your names and do a replace on $play_envir to remove spaces, underscores etc
    There are 10 types of people on CodingForums,
    Those who understand Binary and those who dont.
    Get Cloud Hosting now from only£59 / month


 
Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •