Show next record (that matches the criteria)

17 posts by 2 authors in: Forums > CMS Builder
Last Post: September 7, 2009   (RSS)

This line:

$tile_fields = array('floor_tile', 'floor_grout', 'shower_wall_1');

lists the fields that you want looked up in tile_sku. Those fields in your tile_images record will be replaced by records from tile_sku. You'll want to add all your other fields you want looked up too.


So we're speaking the same thing, "tile_images" holds all the images and pulls data from table "tile_details" - what you are calling "tile_sku" above. Now, was there a typo above (the bold bit)? Don't you mean that that line of code is telling the page which fields in "tile_images" table need to be replaced with information from the "tile_details" table?

tile_details table only has 3 fields - tile_sku, tile_dimensions, and category (see attached screenshot) - are they the fields I should be adding up above? It throws an error when I do, so I assume that I should not do that.

Your last part of your post is exactly correct, I want to show "tile_sku" from the "tile_detail" table. I have incorporated the above - no errors, but unfortunately, no labels still.

Thanks again. I have reposted the page again.

Re: [benedict] Show next record (that matches the criteria)

Hi Chris,

Any word on this? Sorry to hassle, but we're due in 24 hours.

Cheers.

Re: [benedict] Show next record (that matches the criteria)

By Chris - September 5, 2009

Hi benedict,

Sorry about that. I should have tested with a list page like you have. Please replace this:

$tile_imagesRecord = @$tile_imagesRecords[0]; // get first record
// show error message if no matching record is found
if (!$tile_imagesRecord) {
print "Record not found!";
exit;
}


with this:

// show error message if no matching record is found
if (!@$tile_imagesRecords[0]) {
print "Record not found!";
exit;
}

// get first record
$tile_imagesRecord =& $tile_imagesRecords[0];


That should work. It does here.
All the best,
Chris
Take a bow, mate. You are a rockstar. Works a treat.

Re: [benedict] Show next record (that matches the criteria)

Hi Chris,

Sorry to do this to you, but there's one last issue. All the tile grout fields are pulling their data from a different table, tile_grouts instead of tile_details. I tried duplicating your code with variations, but I get this error:

Fatal error: Cannot redeclare collectrecordvalues() (previously declared in /home/jglimpse/public_html/national/detail.php:24) in /home/jglimpse/public_html/national/detail.php on line 51

I have reattached. Thanks.
Attachments:

detail_006.php 18K

Re: [benedict] Show next record (that matches the criteria)

By Chris - September 7, 2009

Hi benedict,

I think you may have attached an old version of your detail.php page, since there is only a <title> tag on line 51 and I don't see any references to tile_grouts at all.

I've been working on generalizing this solution into a function. I've tested it with multiple fields referencing multiple tables (and even multi-value fields). Would you care to try it? Your STEP 1 code would then be simply:

<?php
require_once "/home/jglimpse/public_html/national/cmsAdmin/lib/viewer_functions.php";

list($tile_imagesRecords, $tile_imagesMetaData) = getRecords(array(
'tableName' => 'tile_images',
'perPage' => '1',
));

// show error message if no matching record is found
if (!@$tile_imagesRecords[0]) {
print "Record not found!";
exit;
}

// get first record
$tile_imagesRecord =& $tile_imagesRecords[0];

// look up related fields from other section(s) and insert them into our record
beta_lookupRelatedFields('tile_images', $tile_imagesRecords, array(
// TODO: list all referencing fields here
'floor_tile', 'floor_grout', 'floor_feature_1', 'floor_feature_2'

));

// TODO: insert function code from forum attachment here
?>


Ultimately, I'd like to get this function (or something similar) into a future CMS Builder release for everyone to use.

If that doesn't work for you, please upload your latest detail.php file which gave you that error and I'll see if I can sort it out for you.
All the best,
Chris