Section Editor Default Values

2 posts by 2 authors in: Forums > CMS Builder
Last Post: July 12, 2013   (RSS)

By gregThomas - July 12, 2013

Hi furcat, 

If you set a default value, any new records created will start to use that default value. But to replace old values you'll have to write a script to replace old default values with the new default values. Something like this should work:

<?php header('Content-type: text/html; charset=utf-8'); ?>
  /* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
  // load viewer library
  $libraryPath = 'cmsAdmin/lib/viewer_functions.php';
  $dirsToCheck = array('C:/wamp/www/test/','','../','../../','../../../');
  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 from 'blog'
  list($blogs, $blogMetaData) = getRecords(array(
    'tableName'   => 'blog',
    'loadUploads' => true,
    'allowSearch' => false,

  foreach($blogs as $blog){
    echo "Checking record ".$blog['num']." <br>";
    if($blog['title'] == "test"){
      mysql_update('blog', $blog['num'], null, array('title' => 'Default Title'));
  echo "Script Complete";

This is just example code, so you'll have to make a few changes to get it working with your site. Ensure you make a full back up of your database before running this script.

So I've set up a getRecords function to retrieve all of records from my blog section. Then it cycles through them using a foreach loop, and checks if the title matches an old value (in this case test). If it does, then a mysql_update function is used to replace the title of that record with a new value (in this case Default Title). 

Let me know if you have any questions.



Greg Thomas

PHP Programmer -