images not viewing

9 posts by 3 authors in: Forums > CMS Builder
Last Post: June 20, 2013   (RSS)

By knight_oWL19 - June 16, 2013

Hi all,

here is my block of code for displaying images on my homepage:

<?php if ($upload = @$homepageRecord['images'][0]):?>
                                        <img src="<?php echo $upload['urlPath'] ?>" width="71" height="54" alt="" />
                                        <?php endif?>

is there any reason why this is not working?  :)

Many Thanks,

eldon

By gregThomas - June 17, 2013

Hi Eldon,

In what way is it not working? Is the image tag not being created at all, or is it not loading the image inside of the image tag?

Would it be possible to attach or post the entire code for the page?

Thanks!

Greg

Greg Thomas







PHP Programmer - interactivetools.com

By Jason - June 18, 2013

Hi Eldon,

I took a look at your code and found a couple of things.  The first was a simple typo in the code.  Your home page record set was in a variable called $home_pageRecord, but the code you were using $homepageRecord when trying to output images.

The other problem is that the code $home_pageRecord['images'][0] pulls the first image element out of the array, but it doesn't remove that element.  So if you repeat this line multiple times, it will just output the same image.  The best solution here would be to use a foreach loop like this:

<div id="lower_boxcontain">
  <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?>
</div>

This will go through each element in the array, one at a time.  You don't have to worry about checking for a value first, because if there are no elements in the array at all, then the loop will never execute.

Hope this helps!

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By knight_oWL19 - June 18, 2013

OK, thanks Jason - I will give this a go :)

By knight_oWL19 - June 18, 2013

Hi Jason,

I used the code you sent as follows:

        <div id="lower_boxcontain">  <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?>
                                          <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?>
                                          <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?>
                                          <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?></a></div>
      </div>

Now I'm getting the following error when I load the page: 

Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 130 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 130 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 133 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 133 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 136 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 136 Notice: Undefined index: images in /home/enlig124/public_html/index.php on line 139 Warning: Invalid argument supplied for foreach() in /home/enlig124/public_html/index.php on line 139

index available at:  http://enlightenthesoul.com/index.php

Help!

Thanks,

ko19

By Jason - June 19, 2013

Hi,

The error here means that there is no field called "images" in home_page section of the CMS.  I would first check that section and make sure that the name is right.  That should take care of the issue.  Also, you won't need to repeat the foreach loop 3 times.  The loop means that it will output all of the uploads in that field.  If you duplicate the code 3 times, then you will get all the images repeated.

Hope this helps

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By knight_oWL19 - June 19, 2013

Hi Jason,

So like this?  images is the name of the folder they are found in. 

 <div id="lower_boxcontain"> <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
    <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
    <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
    <?php foreach ($home_pageRecord['images'] as $upload): ?>
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" />
  <?php endforeach ?></a></div>

I have an image that is loading correctly on about page.  code looks like this. 

<p><?php foreach ($aboutRecord['images'] as $index => $upload): ?>
                    <img src="<?php echo $upload['urlPath'] ?>" width="390" height="243" alt="" />
                                        <?php endforeach ?></p>

sory not a php guy, just muckin through this. 

ko19

By Jason - June 20, 2013

Hi,

I took a look at the page again and it looks like you are outputting 4 images, however, they don't look like they are coming from the CMS.  Is that right?

The foreach loop method that I showed you is only used when you are trying to output images that have been uploaded directly to a record in the CMS through an upload field.  Do you have a separate upload field in your home page section?  If so, you can use this code to output all the images uploaded to that section:

<div id="lower_boxcontain"> 
  <?php foreach ($home_pageRecord['images'] as $upload): ?>    
    <img src = "<?php echo $upload['urlPath'];?>" width = "71" height = "54" alt = "" /> 
  <?php endforeach
</div>

This code assumes that your upload field in your homepage section is called "images".  So in this case, if you uploaded 4 images to that upload field, all 4 would be output using this 1 foreach loop.

Hope this helps.

---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/