Jump to content

how do you check if a container field is empty?


This topic is 6943 days old. Please don't post here. Open a new topic instead.

Recommended Posts

I am having trouble finding if a container field is empty or not.

In English:

If containerfield is not empty - get the image and display it.

Here is what I have (and does not work) in PHP

if($findData['Coverimage'][0] != '') { get the image }

-The field cover image is a container field.

-I can get the image without the if statement, however not all records have images.

Link to comment
Share on other sites

so... thought I had it... but

if($findData['Coverimage'][0] != NULL) { get the image } - works and records with images display correctly.

However, when I find some records that I think are NULL, it still tries to put an image there, giving a 'blank image' logo and the alt tag.

So I am back at square one.

Link to comment
Share on other sites

ok...

Here is what you do in this case.

One of the geat things about php is that it allows you to break the code and write pure html then put the code back together.

Example:

<?php

if($findData['Coverimage'][0] != NULL) {

?>

<img src="<?php echo $findData['Coverimage'][0]; ?>">

<?php

}else{ ?>

no image...

<?php } ?>

Basically, I wrapped the PHP code around the HTML. So when it finds an image it will write a completely new html tag. If not, it will write "no image...".

Copy and paste the code above and you should see what I'm talking about.

I think that is what you are looking for.

~Addam~

Link to comment
Share on other sites

thank you for answering so quickly:

There are some errors in your code.

1.) echo $findData['CoverImage'][0]; will not work with container fields.

2.) Your code is essentially what I had and using old filemaker 5/6 code here it is:

<img src="http://localhost:591/FMPro?-db=Publication.fp5&-recid=<? echo $recid; ?>&Coverimage=&-img" alt="cover" width="134" align="right" hspace="8" vspace="5">

so... if you solve this, you are better than any filemaker PHP guru alive. So far an elite group of experts have been unable to cleanly and effectly show, test or use images from container fields in filemaker.

Link to comment
Share on other sites

  • 1 month later...

Quite late on this one, but hey ...

What I do is create a calculation field in the database (checkImg) that checks to see if there is anything in the container field. If so, the calculation resolves to 1, if not, 0. Then I run the if statement on the checkImg field. Eg:

if ($findData['checkImg'][0] == 1) {

// display image;

}

Works like a charm.

Bear in mind I mostly use FX.php, which comes with a file (image_proxy.php) that handles the actual image display and retrieval with it's own syntax.

Cheers,

Kevin

Link to comment
Share on other sites

  • 2 weeks later...

I forgot to post an update to say what we did to solve things:

Basically Kevin's suggestion of a calculation field is the correct answer and it will work in FM5/6.

However for FM7, the image proxy is the only way to got, but the image proxy is very very clunky and doesn't work as well as we would like.

What would be great would be a simple php function that simply does the same as cdml without all the extra features of image proxy.

$getimage['fieldname']; // would return the image.

maybe someday we'll get this developed.

Link to comment
Share on other sites

This topic is 6943 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.