How to generate code for single record section?

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

Re: [Ridder7NO] How to generate code for single record section?

Hi Ridder7NO,

Are you trying to create getRecords code for a single record? If you are then you can do this:

If you go to the code Generator in the cmsAdmin area then select Code Generator under the admin area. You should see a link called Detail Page for getting a single record from the database, click on this.

On the Code Generator Details page select your single record from the Select Section drop down. Under the which record area select Single record sections: Load first record in database

This should give you a getRecord function that looks something like this:

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('C:/wamp/www/','','../','../../','../../../');
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 'tableNametableName'
list($tableNameRecords, $tableNameMetaData) = getRecords(array(
'tableName' => 'tableName',
'where' => '', // load first record
'loadUploads' => true,
'allowSearch' => false,
'limit' => '1',
));
$tableNameRecord = @$tableNameRecords[0]; // get first record
if (!$tableNameRecord) { dieWith404("Record not found!"); } // show error message if no record found


Thanks
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] How to generate code for single record section?

By Ridder7NO - October 12, 2012 - edited: October 12, 2012

Thank you so much for trying to help, greg, but what I meant was:

On my websites frontpage, I have things that repeat (multi), such as a News list etc. That's working perfectly.

But...

Also, I have content that I would like to be shown on each page, but it should not repeat (like news lists etc), like a general footer text, that should be the same on every page, but that I could change in CMS.

I'm talking about a single editor for a single place on the page, without needing ID in the URL.

The detail code wouldn't let me do that, as it required a specific ID in the URL to let the data to be shown.

Hope you understand.

Thank you in advance.

- Ridder7NO

Re: [Ridder7NO] How to generate code for single record section?

So you want to load the same content from the same single record section every time you load the page?

I think the getRecord function I put in the post above will allow you to do this. As it has allowSearch set to false and a limit of 1, it will always return the only record that is stored in that single record section. I'll give you an example of how to use it.

So lets say you have a single record section and one of the fields is footer. If you add the code I posted above to top of your page after you've called the viewer_functions.php file. Then in the place you want to display your footer text you would have something like:

<footer>
<?php echo $tableNameRecord['footer']; ?>
</footer>


Thanks!
Greg Thomas







PHP Programmer - interactivetools.com

Re: [greg] How to generate code for single record section?

Thank you so much! :D

This is great! Thanks for helping me :)