INSERT INFORMATION FROM ONE SECTION EDITOR INTO ANOTHER - Mar 17th, 2011


Sagentic had this challenge:

We have a section called "products" .

Then we have a section called "pricing" that allows you to enter in different sizes of that product and the price. The
first field in this section is a list that pulls the name of the product from the "products" section.

In short, I want to pull all "pricing" entries for Metal Garden Sheds and put it on the "product" page for Metal Garden
Sheds - all "pricing" entries for Wood Garden Sheds and put it on the "product" page for Wood Garden Sheds - etc....

Dave Edis from Interactive Tools observed:

What you want to do is have your first viewer that loads the product accept "url searching" like this: products.php?4
That's the default so that should be fine.

For your price viewer you want it to ignore the search values and hard code the search as a where. That's because you
want to base the search off the value of the product record, not what's in the url. First add a line to get the escaped
productName value:



$escapedProductName = mysql_real_escape_string( $productsRecord['name'] );


Next add this in your price viewer code:



'allowSearch' => false,
'where' => " product = '$escapedProductName' ",


ANOTHER EXAMPLE
Here’s an example of how to use this approach to restrict the records shown on a video list page to only those that
belong to a specific exhibition.

For this example 2 multi record editors are involved.

One multi record editor, called “exhibitions” contains a separate record for each exhibition. Each record has a
field for a unique exhibition_name and an upload field containing a series of still images of those exhibitions. The
exhibitions detail page has a link to the video list page with the exhibitions record number appended .

The other, called “videos” has a separate record for each video with a field for the exhibition_name (which gets
it’s value from a radio button list populated from the exhibition_name field of the exhibitions editor) and an upload
field containing one of the video taken at that exhibitions.


<a href='<a href='videos.php?num=<?php echo $exhibitionsRecord['num'] ?>'>WATCH THE VIDEO FROM THIS EXHIBITION</a>


Then in the video list page in the get records area:


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

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_server/','','../','../../','../../../');
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 records
list($exhibitionsRecords, $exhibitionsMetaData) = getRecords(array(
'tableName' => 'exhibitions',
));
$exhibitionsRecord = @$exhibitionsRecords[0]; // get first record
$escapedExhibitionName = mysql_real_escape_string( $exhibitionsRecord['exhibition_name'] );


// load records
list($videosRecords, $videosMetaData) = getRecords(array(
'tableName' => 'videos',
'allowSearch' => '0',
'where' => " exhibition_name = '$escapedExhibitionName' ",
));

?>


And in the body of the videos list page a straightforward (except I’ve included the MaxWords function that you can
find in the recipe “MAXWORDS - LIMITING THE NUMBER OF WORDS SHOWN ON A PAGE”):


<table>
<?php foreach ($videosRecords as $record): ?>
<tr>
<td>
<?php foreach ($record['list_image'] as $upload): ?>
<a href="<?php echo $record['_link'] ?>"><img src="<?php echo $upload['thumbUrlPath2'] ?>" width="<?php echo
$upload['thumbWidth2'] ?>" height="<?php echo $upload['thumbHeight2'] ?>" alt="" /></a>
<?php endforeach; ?>
</td>
<td><a href="<?php echo $record['_link'] ?>"><?php echo $record['video_title'] ?></a><br /></td>
</tr>
<tr>
<td colspan="2">
<?PHP echo maxWords($record['description'], 25);
?>...<a href="<?php echo $record['_link']; ?>">Read More...</a></td>
</tr>
<tr>
<td colspan="2"><hr align="center" width="300" color="#99945e"/></td>
</tr>
<?php endforeach; ?>
</table>


NOTE: If you have other tables being accessed in your get records calls, you may have to include the line:


'allowSearch' => false,


in those calls, so that the search at the end of the URL does not affect the records returned from those tables. (This
will cause some very strange results on your pages)



The materials on this web site have been created for use with CMS Builder content management software. CMS Builder software is published and licensed for use by InteractiveTools.com. Please contact Interactive Tools for information on the downloading of the software or the purchasing of licenses.


Terms of Service