a.beam.reach Posted April 26, 2007 Share Posted April 26, 2007 I am wondering how to ignore lines of PHP code if the applicable variable is empty. For example in the code below. . . . if the variable $r is empty. . .. I would like the entire line: echo "http://www.mysite.com/images/$r/1" to be ignored. Can you tell that I am very novice!!!! I am learning though. <? // SET GALLERY OPTIONS HERE // ----------------------- // Set Gallery options by editing this text: $q =$_POST['q']; $r =$_POST['r']; echo "http://www.mysite.com/images/$q/1" echo "http://www.mysite.com/images/$r/1" ?> Link to comment https://forums.phpfreaks.com/topic/48732-solved-if-variable-is-empty-ignore-lines-in-php/ Share on other sites More sharing options...
LazyJones Posted April 26, 2007 Share Posted April 26, 2007 $q =$_POST['q']; $r =$_POST['r']; if(!empty($q)) { echo "http://www.mysite.com/images/$q/1"; } if(!empty($r)) { echo "http://www.mysite.com/images/$r/1"; } Link to comment https://forums.phpfreaks.com/topic/48732-solved-if-variable-is-empty-ignore-lines-in-php/#findComment-238853 Share on other sites More sharing options...
xenophobia Posted April 26, 2007 Share Posted April 26, 2007 If $_POST['q'] adn $_POST['r'] is a text box then: if(trim($r) != ""){ echo ......; } If the $_POST['r'] is an option button or checkbox then: if(isset($_POST['q'])){ echo .......; } Link to comment https://forums.phpfreaks.com/topic/48732-solved-if-variable-is-empty-ignore-lines-in-php/#findComment-238854 Share on other sites More sharing options...
a.beam.reach Posted April 26, 2007 Author Share Posted April 26, 2007 Thank you LazyJones and xenophobia. . .. I did not get a chance to try your suggestion xenophobia. . . . as I had already tried the suggestion of LazyJones. It worked great! I did notice the suggestions were slightly different. Guess there is more than one way to skin a cat! Thanks to you both. Trevor Link to comment https://forums.phpfreaks.com/topic/48732-solved-if-variable-is-empty-ignore-lines-in-php/#findComment-238862 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.