Skip to main content
Inspiring
September 12, 2007
Question

Show if field is not empty - PHP/MySQL

  • September 12, 2007
  • 2 replies
  • 1271 views
Is there a way I can only show bits of a page if a recordset has entries in a certain field, automatically hiding the area if the field is empty. (PHP/MySQL)

To put it in real terms, I have loads of products listed in a repeating table. If a product has a photo gallery related to it there is a 1 entered in 'photos' field, it has a video attached here is a 1 entered in 'videos field and likewise for reviews it will have a 1 entered in the reviews field.
What I'd like to have is a photo, video and review icon/link in the 'master table' which only appears in the repeated products that have a 1 listed in that field and have them not appear at all when there is a 0 in the field.

Can anyone help me figure it out
This topic has been closed for replies.

2 replies

Inspiring
September 17, 2007
Thanks guys, I tried both methods and Günter's route worked best. The result is exactly what I was looking for and I feel I have another handy tool in my PHP beginners toolkit as a result.

Thanks again.

Dave
September 12, 2007
If you don't have ADDT, maybe this free old but very pratical extension:

http://www.brettbrewer.com/component/option,com_vfm/Itemid,41/do,view/file,PHP_SIRFCIT.mxp/

Regards,
Márcio
Inspiring
September 13, 2007
Thanks Márcio,

If ADDT will do that for me I'll buy it.
Before I get my credit card out can you just confirm that ADDT will allow me to show or hide an area according to a field condition?

Cheers

Dave
Günter_Schenk
Inspiring
September 13, 2007
ADDT is certainly a great help, as it - among many other features - will allow you define whatever page element as "show/hide" based on a query result -- for this it´s using a so-called "condition builder" which lets you do that without coding.

However you can achieve the same result without needing to resort to ADDT -- by using a basic "if" condition that´s checking the respective table column for having the value "1" stored, and if so, display the page segment

The following 3 examples should work when replacing the sample "queryname" with the query name your page is actually using:

<?php if ($row_queryname['photos'] == '1') {?>
display photo icon here
<?php }?>

<?php if ($row_queryname['videos'] == '1') {?>
display video icon here
<?php }?>

<?php if ($row_queryname['reviews'] == '1') {?>
display videos icon here
<?php }?>