Restrict records shown to those in a specific group
5 posts by 2 authors in: Forums > CMS Builder
Last Post: March 17, 2011 (RSS)
By gkornbluth - March 17, 2011 - edited: March 17, 2011
On a site I’m building, I’m trying to restrict the records shown on a list page to only those that belong to a specific group, and I’m almost there (I think).
I’m attempting to do this with the code Dave suggested at the end of http://www.interactivetools.com/iforum/gforum.cgi?post=64168 in answer to Saginetic's query.
So far, I’ve created 2 multi record editors.
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.
THE PROBLEM
I’d like that video list page to list only the videos that pertain to that exhibition.
However, using the code below, the correct record number of the exhibition is appended to the video link (record 1 or 2) , but the video list page always show only one video, which is actually the last video record (record 3)
I hope that someone's done this before and can see where I’m going wrong, or can suggest a better approach.
Thanks,
Jerry Kornbluth
Here’s the code for the link on the exhibitions detail page:
<a href='<a href='videos.php?<?php echo $exhibitionsRecord['num'] ?>'>WATCH THE VIDEO FROM THIS EXHIBITION</a>
Then in the video list page in the get records area:
// 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' => false,
'where' => " exhibition_name = '$escapedExhibitionName' ",
));
And in the body of the videos list page a straightforward:
<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>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Restrict records shown to those in a specific group
By Jason - March 17, 2011
I think the issue here is that you're not pulling out the correct exhibition record. There is nothing in your query that would pull out a record based on the number in the url. And since the number in the url has no variable name, the search won't happen automatically. That is why you're probably getting the videos associated with the last exhibition record created. Try changing your link to this:
<a href='<a href='videos.php?num=<?php echo $exhibitionsRecord['num'] ?>'>WATCH THE VIDEO FROM THIS EXHIBITION</a>
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/
Re: [Jason] Restrict records shown to those in a specific group
By gkornbluth - March 17, 2011 - edited: March 17, 2011
Still almost there
The correct videos now show on the video list page, but when any other record then #1 is accessed, I get a
"Warning: Invalid argument supplied for foreach() in /hsphere/local/home/c323748/margiekelk.com/videos.php on line 96" error, instead of the page masthead image which is pulled from the single record common_information editor,
and I lose all but one of the navigation links pulled from the multi record navigation editor.
The link is http://50.6.159.105/exhibitions.php (click on an exhibition and then click on the video link.)
Thanks,
Jerry
Here's the actual get records code I'm using on the videos list page:
<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/hsphere/local/home/c323748/margiekelk.com/','','../','../../','../../../');
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($common_informationRecords, $common_informationMetaData) = getRecords(array(
'tableName' => 'common_information',
'limit' => '1',
));
$common_informationRecord = @$common_informationRecords[0]; // get first record
// 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' ",
));
// load records
list($navigationRecords, $navigationMetaData) = getRecords(array(
'tableName' => 'navigation',
));
?>
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [gkornbluth] Restrict records shown to those in a specific group
By Jason - March 17, 2011
I'm not able to see that line, but based on the code I can see, I would guess that it your query getting your navigation list is being affected by the search. All we need to do here is turn off the search:
// load records
list($navigationRecords, $navigationMetaData) = getRecords(array(
'tableName' => 'navigation',
'allowSearch' => false,
));
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/
Re: [Jason] Restrict records shown to those in a specific group
By gkornbluth - March 17, 2011
It's so good that you're soooo good at this.
Thanks,
Jerry
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php