Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Retrieve first record that contains an image

Featured Replies

Hi,

I'm trying to implement a CDML query that returns the newest record that contains an image. I can't for the life of me figure out a way to skip newer records that don't contain an image and return the first one that does.

(Explanation: The database provides news articles for our website, some of which contain images. I'm trying to build thumbnail links into the home page to provide shortcuts to the latest articles/content, maximum of 4. Obviously I want to avoid records that don't give me an image to use as a thumbnail.)

Any ideas?

Cheers,

Kevin Futter

First, using FM to store the images is a waste of db functionality. You will be better advised to store the images in a folder and refer to them from the individual records to which they relate. You may be able to control the thumbs through size designations on the html (format file) page, thus one image in storage. Then again, you may not and may need two images. You certainly can link FMP records to images stored elsewhere.

There are also different approaches to the problem (whether a link or an image is in the field). One approach is to control it through the find criteria. Another is to control it through an [FMP-If] on the results page.

Bon chance.

  • Author

I don't supply the images myself - staff upload them directly into the database; getting them to upload them into a server folder first and then link them to the database just isn't practical - it's confusing enough for some of them the way it is. But that wasn't the question ...

I need to sort it out in the find (hence the term 'query' in my original post - this is what most database 'finds' are called), not in the format file using FMP-If.

Since you imply that this can be done, I'd be appreciative of an explanation.

Cheers,

Kevin Futter

Not only is the use of FM to store the images a waste of db functionality, you cannot perform a search on a container field. Nor can you index or sort container fields.

You cannot use the FMP-If tag with a container field to determine if it contains an image.

You need to redesign your db to allow you to identify the records with images.

Then you will be able to either perform a complex search and sort or use the FMP-If conditional.

It is all a matter of design; db and format files.

  • Author

Thanks, I was beginning to suspect changes might be needed to the database. But using references in container fields is just out of the question for us, whether it's best practise or not.

Cheers,

Kevin Futter

You can create a Calculation field like this:

is_image: If(IsEmpty(myimgfld),0,1)

Hence, the search could look like this:

/FMPro?-db=mystories.fp5&-format=listing.html&is_image=1&-sortfield=story_date&-sortorder=descending&-find

The first record returned should be the latest with an image.

Good Luck.

Garry

Solid Garry.

  • Author

Thanks Garry - I'd just finished implementing this exact solution when I came back here to see your reply.

Cheers,

Kevin Futter

Create an account or sign in to comment

Important Information

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.