Help with if statement

Discussion in 'PHP' started by Qal, Apr 8, 2008.

  1. #1
    Hi,

    I currently have this code which checks if the getCustomData() has an integer to process the next function. If empty of "0", it doesn't fetch payment.php

    
    <?php $price = (int) getCustomData(); 
    if( $price ) {
    ?>
      <div style="text-align:center;"> Price : $<?php echo getCustomData();?>
        <?php require( 'payment.php' ) ?>
        </form>
      </div>
    <?php } ?>
    Code (markup):
    However, now payment.php has changed a lot so I need to make it so that if "0" or "free" is passed as getCustomData(), payment.php should not be parsed/processed. If that makes sense?

    Many thanks
     
    Qal, Apr 8, 2008 IP
  2. mulari

    mulari Peon

    Messages:
    45
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try:

     
    mulari, Apr 8, 2008 IP
  3. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    nope, that still parses the payment.php
     
    Qal, Apr 8, 2008 IP
  4. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i duhno if i understood the question rite

    by why dont u use the break command
     
    PowerExtreme, Apr 8, 2008 IP
  5. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I just don't want to parse/process payment.php if the getCustomData() is set to free or '0'
     
    Qal, Apr 8, 2008 IP
  6. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?php
    $price = (int) getCustomData();
    if( $price != 0 && $price != 'free' ) {
    ?>
    <div style="text-align:center;"> Price : $<?php echo getCustomData();?>
    <?php require( 'payment.php' ) ?>
    </form>
    </div><?php }
    else
    break;
    ?>


    Try it out
     
    PowerExtreme, Apr 8, 2008 IP
  7. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Erm..doesn't work either. :-(
     
    Qal, Apr 8, 2008 IP
  8. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Try

    <?php
    $price = getCustomData();
    if( $price != 0 && $price != 'free' ) {
    ?>
    <div style="text-align:center;"> Price : $<?php echo getCustomData();?>
    <?php require( 'payment.php' ) ?>
    </form>
    </div><?php }
    else
    break;
    ?>
     
    PowerExtreme, Apr 8, 2008 IP
  9. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Aah, the very first one posted by mulari worked. My bad, I wasn't puting 0 or free inthe right field.

    Many thanks, mulari and powerextreme. :)
     
    Qal, Apr 8, 2008 IP
  10. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    Just one more request: Is it possible to NOT parse/process payment.php when the getCustomData is EMPTY, but only on 0 or free?

    Many thanks
     
    Qal, Apr 8, 2008 IP
  11. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #11
    if u use this code

    <?php
    $price = getCustomData();
    if( $price != 0 && $price != 'free' ) {
    ?>
    <div style="text-align:center;"> Price : $<?php echo getCustomData();?>
    <?php require( 'payment.php' ) ?>
    </form>
    </div><?php }
    else
    break;
    ?>
    Code (markup):
    It will happen that way only i guess
     
    PowerExtreme, Apr 8, 2008 IP
  12. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #12
    nope, if getCustomData is empty, it doesn't parse payment.php, whereas I want it to parse when its EMPTY, but NOT when 0 or free is defined.
     
    Qal, Apr 8, 2008 IP
  13. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #13
    <?php
    if($price == NULL) {
    require( 'payment.php' );
    }
    ?>

    you have to add that code to do that
     
    PowerExtreme, Apr 8, 2008 IP
  14. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #14
    
        <?php $price = getCustomData();
    		if( $price != 0 && $price != 'free' && $price == NULL ) { 
    	?>
    
    Code (markup):
    right?

    doesn't work. :-(
     
    Qal, Apr 8, 2008 IP
  15. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Change the statment too

    $price != 0 || $price != 'free' || $price == NULL
    Code (markup):
     
    PowerExtreme, Apr 8, 2008 IP
  16. EnPassant

    EnPassant Active Member

    Messages:
    612
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #16
    A little confused. Which conditions do you want it to process payment? and which conditions not?

    When it is 0 or free it does NOT process payment?
    and when it is empty it does process payment?

    Because 0 is considered empty. I mean $price == 0 is the same as $price == NULL. Correct me please.

    So I think when you tell the script to not process payment when its null or free, then contradict by wanting it to process when its empty (null)-- Hope I understand you.
     
    EnPassant, Apr 8, 2008 IP
  17. PowerExtreme

    PowerExtreme Banned

    Messages:
    2,118
    Likes Received:
    75
    Best Answers:
    0
    Trophy Points:
    0
    #17

    i assume 0 and null are diffrent - null is empty and 0 is a value . correct me if i am wrong
     
    PowerExtreme, Apr 8, 2008 IP
  18. EnPassant

    EnPassant Active Member

    Messages:
    612
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
    #18
    I said this because in the php manual it says:

    The following things are considered to be empty:

    "" (an empty string)
    0 (0 as an integer)
    "0" (0 as a string)
    NULL
    FALSE
    array() (an empty array)
    var $var; (a variable declared, but without a value in a class)
     
    EnPassant, Apr 8, 2008 IP
  19. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #19
    payment.php is now processed/parsed on EMPTY and '0' value, but not only on 'free'. It should also NOT be processed on '0'.
     
    Qal, Apr 9, 2008 IP
  20. Qal

    Qal Peon

    Messages:
    92
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #20
    Tried this and it works now as desired.

    if( $price_cost != 0 || $price_cost != 'free' && $price_cost == NULL )
    Code (markup):
    Thanks all for help. :)
     
    Qal, Apr 9, 2008 IP