evolooshun Posted April 8, 2010 Share Posted April 8, 2010 I need to put the following code into an if / else statement like similar to this code. <?php if ( $price > "0.00" ) { print("Call for pricing"); } else { print("18001234567"); } Where the first line would be the same but changing the "Call for pricing" with this code: <div class="product"> <input value="<?php print($itemID); ?> <?php print($title); ?>" class="product-title" type="hidden"> <input value="<?php print("$thisPic"); ?>" class="product-image" type="hidden"> <input value="<?php print("$price"); ?>" class="product-price" type="hidden"> <div title="Add to cart" role="button" tabindex="0" class="googlecart-add-button"> </div></div> I cant figure out how to format it properly to not break the <?php print($itemID); ?> inside the if statement. Please help, Ive tried everything I can think of. I think its supposed to be something like this: <?php if ( $price > "0.00" ) { echo "<div class="product">"; echo "<input value="<?php print($itemID); ?> <?php print($title); ?>" class="product-title" type="hidden">"; echo "<input value="<?php print("$thisPic"); ?>" class="product-image" type="hidden">"; echo "<input value="<?php print("$price"); ?>" class="product-price" type="hidden">"; echo "<div title="Add to cart" role="button" tabindex="0" class="googlecart-add-button"></div></div>"; I just cant figure out how to format it properlly Link to comment https://forums.phpfreaks.com/topic/198046-if-statement-formating/ Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 There are many ways to do that. If the 18001234567 is static you can do it like this: <?php if( $price > "0.00" ): ?> <div class="product"> <input value="<?php print($itemID); ?> <?php print($title); ?>" class="product-title" type="hidden"> <input value="<?php print("$thisPic"); ?>" class="product-image" type="hidden"> <input value="<?php print("$price"); ?>" class="product-price" type="hidden"> <div title="Add to cart" role="button" tabindex="0" class="googlecart-add-button"> </div></div> <?php else: ?> <p>18001234567</p> <?php endif; ?> Link to comment https://forums.phpfreaks.com/topic/198046-if-statement-formating/#findComment-1039164 Share on other sites More sharing options...
evolooshun Posted April 8, 2010 Author Share Posted April 8, 2010 works perfect, so you just broke down the if statement into pieces then used an endif. thank you Link to comment https://forums.phpfreaks.com/topic/198046-if-statement-formating/#findComment-1039166 Share on other sites More sharing options...
the182guy Posted April 8, 2010 Share Posted April 8, 2010 Yes, and you can improve your if statement by using something like this instead... it's not good practice to put numbers in strings like you did <?php if( (float)$price > 0 ): ?> Or if you're already certain $price is a float the you can remove the (float) cast. Link to comment https://forums.phpfreaks.com/topic/198046-if-statement-formating/#findComment-1039173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.