PHP If checking for Uploads not working with PHP 8

6 posts by 2 authors in: Forums > CMS Builder
Last Post: August 15   (RSS)

By gkornbluth - August 15

Hey Phil,

Have you tried just deleting the None?

If hat doesn't work, how about using an elseif instead of the else in the second half.

One of those might work.

Jerry Kornbluth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By pacolvin - August 15

Jerry,

I just tried deleting the None and that breaks the whole page.  Just get a blank page when loading.

I can give the elseif a try a bit later and see if that works.  I'm not sure it will work since I have to test the first if to see if there are any photos (uploads) for that record.  That is what the None is doing now.

Phil

By gkornbluth - August 15

There's both a ! and a None in that line I'm not sure, but that seems to be a double negative.

Try reversing the logic. IE if records then show records, else if !records leave it blank

                                <div class="photo-gallery">
                                    <div class="row photos" style="padding-bottom: 20px;">
                                        <?php if ($record['photos']):?>
<?php foreach ($record['photos'] as $index => $upload): ?>
                                                <?php if ($index >= 4) { continue; } // limit uploads shown ?>
                                                <div class="col-sm-6 col-md-4 col-lg-3 item">
                                                    <a href="<?php echo htmlencode($upload['urlPath']) ?>" data-lightbox="photos<?php echo htmlencode($record['num']) ?>"><img class="img-fluid" src="<?php echo htmlencode($upload['urlPath']) ?>"/></a>
                                                </div>                                                 
                                            <?php endforeach ?>
                                       <?php elseif (!$record['photos']):?>&nbsp;                                            
                                        <?php endif ?> 
                                    </div>
                                </div>
The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By pacolvin - August 15

When I deleted the None previously, I also deleted the : which is what broke the page.  Keeping the : at the end of the IF statement and removing the None works on PHP 7.4 and 8.

Thanks for the suggestions.

Phil

By gkornbluth - August 15

Glad you got it working.

Have you checked out the CMSB Cookbook?

Free trial with the link below

Jerry Kornbuth

The first CMS Builder reference book is now available on-line!

Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php