Gossamer Forum
Quote Reply
IF ?
Is there a way of adding some html code (ie : <br> ) only if a field is full and not if it's empty ?
In the same Idea, is there a way of adding different html code in the results page in function of the chosen category (If the category searched is "business", i'd like to add "you're on business page and blabla...", if it's "marketing, "the market, today"... etc.)
Thanks a lot
Serge
Quote Reply
Re: IF ? In reply to
Since you seem to want a number of different things, I'll give you the syntax for the commands you want and you can apply them yourself.

Code:
|; # to close off a previous print qq| statement
if (condition) {
print qq|whatever|;
}
elsif (condition) {
print qq|something else|;
}
else {
print qq|another something|;
}
print qq|

If you want to test for whether there is a value in a variable -- whether the field has anything in it or not -- for the "condition" part, just use

$rec{'fieldname'}

So, if you wanted to print a <BR> only if the field "Address" had something in it, you would use

Code:
if ($rec{'Address'}) {
print qq|<BR>|;
}

Does this help?

------------------
JPD





Quote Reply
Re: IF ? In reply to
Thanks a lot

Is there a way of doing something like

if ($rec{'Address'}="Ford")

{ print qq|<BR>|;}

I tried but it doesn't work

Thanks
Quote Reply
Re: IF ? In reply to
Yes, you can do something like it, but your syntax is a little off.

if ($rec{'Address'} eq "Ford")

{ print qq|<BR>|;}


You only use an = sign if you are assigning a value to a variable. If you want to test whether a variable is equal to a variable, you use == for numbers and eq for text.


------------------
JPD





Quote Reply
Re: IF ? In reply to
Waow a great thank you, JP ! )
(for your 2 replies)
just - if I dare - What is the syntax if it's <b>different</b> than "Ford" ???
Quote Reply
Re: IF ? In reply to
You mean "not equal"?

You can go two ways with this:

if ($rec{'Address'} ne "Ford")
{ print qq|<BR>|;}

or

unless ($rec{'Address'} eq "Ford")
{ print qq|<BR>|;}

Both of those will do the same thing.


------------------
JPD





Quote Reply
Re: IF ? In reply to
Thanks a lot, JPD, it work fine !