RESET THE VALUE OF A FIELD IN A MULTI RECORD TABLE (DATE FIELDS ONLY) - Aug 29th, 2014


My client needed to update the value of a date field in all of the records in a multi-record table, where the hidden
field value was “0" (not hidden) with a specific date.

Here’s the approach that we used. The date must be in the format YYYY-MM-DD



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

// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('/path_to_your_root_directory/','','../','../../','../../../');
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 'your_table'
list($your_tableRecords, $your_tableMetaData) = getRecords(array(
'tableName' => 'your_table',
'loadUploads' => true,

));

?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>access-update2</title>
</head>

<body>
<?php foreach ($your_tableRecords as $record): ?>
<?php
mysql_query("UPDATE `{$TABLE_PREFIX}your_table`
SET expiresDate = '2015-04-01'
WHERE hidden = '" . 0 . "'"
)
or die(
"MySQL Error:\n". htmlspecialchars(mysql_error()) . "\n");
$userNum = mysql_insert_id();

?>
<?php endforeach ?>
</body></html>




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