PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
michlcamp
Forum Commoner
Posts: 78 Joined: Mon Jul 18, 2005 11:06 pm
Post
by michlcamp » Tue Dec 20, 2005 2:37 pm
When it's a numeric field ($qty, for example), the IF statement works great like this...
and if $qty is greater than zero, it echo's $qty.
How would you use the IF statement to do the same thing if the field is a text field?
($address2, for example)
thanks in advance.
(you guys are great!)
mc
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Tue Dec 20, 2005 2:44 pm
well obviously you can't use the ">" operator as there's not a quantity against which to compare.
what do you need to know in the "if" condition to make it pass?
Code: Select all
if($somefield == "some text")
echo "it passed";
michlcamp
Forum Commoner
Posts: 78 Joined: Mon Jul 18, 2005 11:06 pm
Post
by michlcamp » Tue Dec 20, 2005 4:22 pm
I want to echo the text if there's ANY text, do nothing if there's NO text...
hawleyjr
BeerMod
Posts: 2170 Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA
Post
by hawleyjr » Tue Dec 20, 2005 4:27 pm
The
Empty Function is what your looking for.
Burrito
Spockulator
Posts: 4715 Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah
Post
by Burrito » Tue Dec 20, 2005 4:28 pm
you could do this:
or this:
Code: Select all
if(strlen($string) > 0)
echo $string;
or you could just echo the string and if there's nothing there it won't show anything
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 4:29 pm
I see this is redundancy, if there is no text contained in the variable, echo'ing it will do nothing essentially.. for your purposes at least. That is unless you are going to have more then
in your if block/..
michlcamp
Forum Commoner
Posts: 78 Joined: Mon Jul 18, 2005 11:06 pm
Post
by michlcamp » Tue Dec 20, 2005 5:15 pm
I ended up using this...worked fine, does what I want it to.
Code: Select all
if ($shipaddr2) { echo "$shipaddr2<br>";}
josh
DevNet Master
Posts: 4872 Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida
Post
by josh » Tue Dec 20, 2005 7:08 pm
true but that doesn't cover everything
Code: Select all
<?
$var = '0';
if ($var) {
// will not output it
}
if ($var!=NULL) {
//will output it
}
?>