Gossamer Forum
Home : Products : DBMan : Customization :

Conditional display of field content

Quote Reply
Conditional display of field content
Could you give me an example of how to do a conditional display of something in relation to a database field content?
That is:
If content == "Something"
then display "something else"
otherwise display "another thing"

Thanks,

Rodrigo Fernandez
Quote Reply
Re: Conditional display of field content In reply to
The easiest example is:

Code:
if ($rec{'SUBJ'} gt $db_default{'SUBJ'}) {
print qq|<$font><a
href="$db_script_link_url&ww=on&$db_key=$rec{$db_key}&view_records=1">$rec{'SUBJ'} $rec{'CRS'}</a></font> |;
}
else {
print qq| |;
}

Translation:

If someone enters a subject, then print the cell in the table with a link going to the detailed view. If someone does not enter a subject, then print a space and go to the next set of variables.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 06, 1999).]

[This message has been edited by Eliot (edited July 06, 1999).]
Quote Reply
Re: Conditional display of field content In reply to
I just want to display something like "Not Available" when a field of the database is empty.
Is there an easy way of doing this?
Thanks
Quote Reply
Re: Conditional display of field content In reply to
Ah, Rodrigo...The example I provided CAN be modified to put something like Not Available!

For example:

Code:
if ($rec{'SUBJ'} gt $db_default{'SUBJ'}) {
print qq|<$font><a
href="$db_script_link_url&ww=on&$db_key=$rec{$db_key}&view_records=1">$rec{'SUBJ'} $rec{'CRS'}</a></font> |;
}
else {
print qq|Not Available|;
}

Another way you could do this is set up a default of "Not Avaiable" for all your fields in the default.cfg (configuration) file. For example:

Code:
Field_Name => [1, 'alpha', 40, 255, 0, '', 'Not Available'],

Hope this helps.

Regards,


------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us

[This message has been edited by Eliot (edited July 07, 1999).]

[This message has been edited by Eliot (edited July 07, 1999).]
Quote Reply
Re: Conditional display of field content In reply to
An even easier way is to use one line:

Print "Not Available" unless ($rec{'subj'});
Print "$rec{'subj'}" if ($rec{'subj'});

I believe my syntax is correct. JP will correct me if I am wrong.


[This message has been edited by mike1 (edited July 07, 1999).]
Quote Reply
Re: Conditional display of field content In reply to
Mike,

Your syntax looks fine, however, a bit messy for my personal taste. Smile I prefer to use if and else statements because they have a more logical flow in the script...but that is just my personal preference...each programmer has 'em.

Regards,

------------------
Eliot Lee
Founder and Editor
Anthro TECH, L.L.C
http://www.anthrotech.com/
info@anthrotech.com
==========================
Coconino Community College
http://www.coco.cc.az.us/
Web Technology
Coordinator
elee@coco.cc.az.us
Quote Reply
Re: Conditional display of field content In reply to
I think the database default definition way will suit my case just fine.
Thanks to all!
You guys are great!
Rodrigo