getting images from another table

9 posts by 2 authors in: Forums > CMS Builder
Last Post: October 3, 2012   (RSS)

By zaba - October 1, 2012 - edited: October 2, 2012

I have 2 tables one called pages and the other called footer.
in pages I have a list field of checkboxes which pulls in from footer the title as a label and image as the value.

on the pages display page I want to display all the images from the footer that have been checked.

I can not figure out how to do this.

Heres the pages code:
How do I get it to display the footer images , that have been checked in the admin section.


<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/xxxxxxx/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'pages'
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => "`num` = '1'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record
if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

?>
<!-- STEP2: Display Record (Paste this where you want your record to appear) -->
<h1>Pages - Detail Page Viewer</h1>
Record Number: <?php echo htmlencode($pagesRecord['num']) ?><br/>
Parent Category: <?php echo htmlencode($pagesRecord['parentNum']) ?><br/>
Name: <?php echo htmlencode($pagesRecord['name']) ?><br/>
File Path: <?php echo htmlencode($pagesRecord['file_path']) ?><br/>
Content: <?php echo $pagesRecord['content']; ?><br/>
Footer Blocks (values): <?php echo join(', ', $pagesRecord['footer_blocks:values']); ?><br/>
Footer Blocks (labels): <?php echo join(', ', $pagesRecord['footer_blocks:labels']); ?><br/>
_link : <a href="<?php echo $pagesRecord['_link'] ?>"><?php echo $pagesRecord['_link'] ?></a><br/>

<!-- STEP 2a: Display Uploads for field 'splash_image' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
Splash Image:
<blockquote>
<?php foreach ($pagesRecord['splash_image'] as $index => $upload): ?>
Upload Url: <?php echo $upload['urlPath'] ?><br/>

<!-- Uploads: Copy the tags from below that you want to use, and erase the ones you don't need.
<br/>
Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

Image Tags:<br/>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<br/>

Extension: <?php echo $upload['extension'] ?><br/>
isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
<hr/>
// end uploads comment tag -->

<?php endforeach ?>
</blockquote>
<!-- STEP2a: /Display Uploads -->

<!-- /STEP2: Display Record -->
<hr/>

<a href="<?php echo $pagesMetaData['_listPage'] ?>">&lt;&lt; Back to list page</a>
<a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>

Re: [zaba] getting images from another table

Hi,

Is the field that stores the list values for the footer images called footer_blocks?

If it is then I would do something like this:



<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php


// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/claytonc/domains/claytoncreative.co.uk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'pages'
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => "`num` = '1'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record
if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

//check that at least one footer image has been selected
if($pagesRecord['footer_blocks:values'][0] > 0){
//create a search string that contains all of the footer_block values.
$additionString = implode(',',$pagesRecord['footer_blocks:values']);

list($footerImage, $footerMetaData) = getRecords(array(
'tableName' => 'footerImageTableGoesHere',
'where' => "num IN ($additionString)",
'loadUploads' => false,
'allowSearch' => false,
));
}

?>
<!-- STEP2: Display Record (Paste this where you want your record to appear) -->
<h1>Pages - Detail Page Viewer</h1>
Record Number: <?php echo htmlencode($pagesRecord['num']) ?><br/>
Parent Category: <?php echo htmlencode($pagesRecord['parentNum']) ?><br/>
Name: <?php echo htmlencode($pagesRecord['name']) ?><br/>
File Path: <?php echo htmlencode($pagesRecord['file_path']) ?><br/>
Content: <?php echo $pagesRecord['content']; ?><br/>
Footer Blocks (values): <?php echo join(', ', $pagesRecord['footer_blocks:values']); ?><br/>
Footer Blocks (labels): <?php echo join(', ', $pagesRecord['footer_blocks:labels']); ?><br/>
_link : <a href="<?php echo $pagesRecord['_link'] ?>"><?php echo $pagesRecord['_link'] ?></a><br/>

<!-- STEP 2a: Display Uploads for field 'splash_image' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
Splash Image:
<blockquote>
<?php foreach ($pagesRecord['splash_image'] as $index => $upload): ?>
Upload Url: <?php echo $upload['urlPath'] ?><br/>

<!-- Uploads: Copy the tags from below that you want to use, and erase the ones you don't need.
<br/>
Download Link: <a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/><br/>

Image Tags:<br/>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>
<br/>

Extension: <?php echo $upload['extension'] ?><br/>
isImage: <?php if ($upload['isImage']): ?>Yes<?php else: ?>No<?php endif ?><br/>
hasThumbnail: <?php if ($upload['hasThumbnail']): ?>Yes<?php else: ?>No<?php endif ?><br/>
<hr/>
// end uploads comment tag -->

<?php endforeach ?>
</blockquote>
<!-- STEP2a: /Display Uploads -->

<?php foreach($footerImage as $row){?>
//You should be able to cycle through all of the fields
//from your footer images here. I'm not sure how your
//records are set up for uploads, so I've set up the loop
// to display one record and then exit.
// If you are unsure how to create a loop to show the
//images paste the code that gets outputted below to
// this forum post.
showme($row);
exit;
}

?>
<!-- /STEP2: Display Record -->
<hr/>

<a href="<?php echo $pagesMetaData['_listPage'] ?>">&lt;&lt; Back to list page</a>
<a href="mailto:?subject=<?php echo urlencode(thisPageUrl()) ?>">Email this Page</a>


You will have to replace the name of the table 'footerImageTableGoesHere' with the name of the table that contains all of the footer images.

I am making a few assumptions here:

That the field footer_blocks is being used for storing the image values.
Your storing the image num in the value for footer block.

Let me know if this doesn't work!

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] getting images from another table

By zaba - October 1, 2012

Thanks Greg,
But I'm all in a muddle.

The Table for the footer images is :

Table Name: footer_blocks
Fields: title, url, image

The other table
Table Name: pages
Contains the field footer_blocks,

this field is set up as a list of check boxes with the data pulled from the table footer_blocks (see attached 16png)

I need to be able to pull in all the images that have been checked in the table pages (together with the title as an alt tag and url as the link). (the page has room to display only 3 so I need to make sure it picks up only the first 3 if more have been checked).


Sorry about this Greg.
I've been messing around and just got in a state.

I'm just pretty much confused as to whats happening in order to achieve this.
Attachments:

picture-16.png 71K

Re: [zaba] getting images from another table

Pulling related items from multiple sections isn't easy to get your head around.

It would be great if you could run the code below at the top of a new page, then paste the outputted array into a new post, as there are two different ways that uploads can be saved into the CMS Builder and I'm not sure which you are using. That way I can give you exactly the code you need to get the images to display along with an explanation of how it works.

//Copy and paste this into the top of a new page.

// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/claytonc/domains/claytoncreative.co.uk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'pages'
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => "`num` = '1'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record
if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

//check that at least one footer image has been selected
if($pagesRecord['footer_blocks:values'][0] > 0){
//create a search string that contains all of the footer_block values.
$additionString = implode(',',$pagesRecord['footer_blocks:values']);

list($footerImage, $footerMetaData) = getRecords(array(
'tableName' => 'footer_blocks',
'where' => "num IN ($additionString)",
'loadUploads' => false,
'allowSearch' => false,
));
}
foreach($footerImage as $row){
showme($row);
exit;
}



Let me know if it's giving you an errors.

Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] getting images from another table

By zaba - October 2, 2012 - edited: October 2, 2012

Hi Greg,

heres the output...
it looks like we are only getting 1 through, there should be 3 in the array. Plus I don't know how to then display the images from here.


Array
(
[_filename] =>
[_link] => javascript:alert('Set Detail Page Url for this section in: Admin > Section Editors > Viewer Urls')
[_tableName] => footer_blocks
[createdByUserNum] => 1
[createdDate] => 2012-09-28 12:13:21
[dragSortOrder] => 1348830801
[num] => 1
[title] => our clients opinion
[updatedByUserNum] => 1
[updatedDate] => 2012-10-01 18:12:13
[url] => 4
[url:label] => /about-us/our-clients-opinion.php
[createdBy.num] => 1
[createdBy.createdDate] => 2012-09-27 16:22:39
[createdBy.createdByUserNum] => 0
[createdBy.updatedDate] => 2012-09-27 16:22:39
[createdBy.updatedByUserNum] => 0
[createdBy.fullname] => xxxx
[createdBy.email] => xxxx
[createdBy.username] => xxx
[createdBy.lastLoginDate] => 2012-10-02 09:34:37
[createdBy.expiresDate] => 0000-00-00 00:00:00
[createdBy.neverExpires] => 1
[createdBy.isAdmin] => 1
[createdBy.disabled] => 0
[createdBy.accessList] =>
[createdBy._filename] =>
[createdBy._link] => javascript:alert('Set Detail Page Url for this section in: Admin > Section Editors > Viewer Urls')
)

Re: [zaba] getting images from another table

My apologies , the code I gave you in the last post had a mistake in it! The getRecords function had 'loadUploads' set to false when it should have been true. If you change that line so that it's true uploads should show in your output.

//Copy and paste this into the top of a new page.

// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/claytonc/domains/claytoncreative.co.uk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'pages'
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => "`num` = '1'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record
if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

//check that at least one footer image has been selected
if($pagesRecord['footer_blocks:values'][0] > 0){
//create a search string that contains all of the footer_block values.
$additionString = implode(',',$pagesRecord['footer_blocks:values']);

list($footerImage, $footerMetaData) = getRecords(array(
'tableName' => 'footer_blocks',
'where' => "num IN ($additionString)",
'loadUploads' => true,
'allowSearch' => false,
));
}
foreach($footerImage as $row){
showme($row);
exit;
}


The reason it is only displaying one record is because I've set it to exit the foreach loop after displaying only the first entry.


Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] getting images from another table

By zaba - October 3, 2012

Thats great..
how do I extract and display the image from the results?
thanks for your help on this!

Re: [zaba] getting images from another table

Hi,

I think the code below should output the images correctly.
<?php
//Copy and paste this into the top of a new page.

// load viewer library
$libraryPath = 'cms/lib/viewer_functions.php';
$dirsToCheck = array('/home/claytonc/domains/claytoncreative.co.uk/public_html/','','../','../../','../../../');
foreach ($dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

// load record from 'pages'
list($pagesRecords, $pagesMetaData) = getRecords(array(
'tableName' => 'pages',
'where' => "`num` = '1'",
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$pagesRecord = @$pagesRecords[0]; // get first record
if (!$pagesRecord) { dieWith404("Record not found!"); } // show error message if no record found

//check that at least one footer image has been selected
if($pagesRecord['footer_blocks:values'][0] > 0){
//create a search string that contains all of the footer_block values.
$additionString = implode(',',$pagesRecord['footer_blocks:values']);

list($footerImage, $footerMetaData) = getRecords(array(
'tableName' => 'footer_blocks',
'where' => "num IN ($additionString)",
'loadUploads' => true,
'allowSearch' => false,
));
} ?>


<?php
foreach($footerImage as $row){
foreach($row['image'] as $picture){ ?>
<img src="<?php echo $picture['thumbUrlPath']; ?>" alt="<?php echo $picture['info2']; ?>" /><br/>
<?php
}
}
?>


I'm assuming the images are stored in a field called 'image', so you might have to change it to something else if they're not.

Let me know if you have any problems!

Thanks
Greg Thomas







PHP Programmer - interactivetools.com