CREATING QR CODES FOR ALL THE RECORDS IN A SECTION - May 5th, 2011


I had a created a multi-record section with a record for each of an artist's client's works.

The artist wanted to be able to generate a single page, three column viewer that showed the QR codes for the URL of the
detail page for each record in that section, along with some identifying information.

The QR images would then be used to create QR stickers for wall labels at an art exhibition.

The records all had an upload field called "image" and a "Title" field for the name of the work.

Here's the code I used for the top of my viewer:

<?php
// load viewer library
$libraryPath = 'cmsAdmin/lib/viewer_functions.php';
$dirsToCheck = array('','../','../../','../../../', '../../../../', '../../../../../');
foreach (
$dirsToCheck as $dir) { if (@include_once("$dir$libraryPath")) { break; }}
if (!
function_exists('getRecords')) { die("Couldn't load viewer library, check filepath in sourcecode."); }

list(
$your_tablesRecords, $your_tableMetaData) = getRecords(array(
'tableName' => 'your_table',
));


?>
<!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">


And here's the code for the body:

<div align="center"><h2>HOME PAGE QR CODE</h2><?php
echo qrCode(array(
'type' => 'url',
'size' => '150', // height & width in pixels
'url' => 'http://your_site.com/'
));
?></div>
<br /> <br />
<div align="center"><h2>INDIVIDUAL IMAGE QR CODES<br /> <br />
<table align="center" width="1200">
<tr><?php foreach ($your_tableRecords as $record): ?>
<?php foreach ($record['image'] as $upload): ?>
<?php $num = $record['num'] ?>

<td align="center" valign="bottom"><img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo
$upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight']?>" />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
<?php
echo qrCode(array(
'type' => 'url',
'size' => '150', // height & width in pixels
'url' => "http:/your_site.com/your_detail_page.php?$num"
));
?><br /><?php echo $record['title'] ?><br /><hr /><br />
</td>
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif; ?>
<?php endforeach ?>
<?php endforeach ?>
</tr>
</table>



Here's a trick from Robin Brayer that helped me get this to work.

To append the record number to the URL you first need to create a variable.

I used:

<?php $num = $record['num'] ?>


Then you can append that variable to the URL in two ways.

1) Then you can concatenate the variable to the URL like this

'url' => 'http://www.elleschorrphotography.com/gallery5detail.php?' . $num


or,

2) If you use double quotes instead of single quotes, you can add the variable directly to the string, like this:

'url' => "http://www.elleschorrphotography.com/gallery5detail.php?$num"



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