simple variable issue (hopefully)

5 posts by 2 authors in: Forums > CMS Builder
Last Post: April 26, 2018   (RSS)

By leo - April 25, 2018

Hi,

You can take a look at the post here: https://www.interactivetools.com/forum/forum-posts.php?Image-from-Multi-record-81293. That may help you get the fist record you want.

Basically, if you want to get the first record of an array ($records), it's $records[0] by default and you can get the model value by $records[0]['model'],

Hope that helps and let me know if you have any questions!

Thanks,

Leo - PHP Programmer (in training)
interactivetools.com

By willydoit - April 26, 2018

Hi Leo,

thanks for your help from what I understand it would seem that by using

 <?php echo htmlencode($records[0]['model'])?> 

it should display the value in the model variable from the first record.  I have tried this but unfortunately I get the same error as before of undefined variable. i also get the same error if I place 

<?php echo htmlencode($record['model']) ?>

in the meta tags which makes me think that the problem is due to it being a list page not a detail page and therefor at this stage the variable either has no value or multiple values.. I know that what I want to do will work on a detail page. As the value of this variable will be the same in all the selected records it doesnt matter which record produces the value, i just thought the first record would be the most obvious one to use.

In case it helps I have copied my head element below as I think I need to edit something in that section with it being a listing page but that is purely guesswork on my part based on no knowledge whatsoever.

<?php header('Content-type: text/html; charset=utf-8'); ?>
<?php
/* STEP 1: LOAD RECORDS - Copy this PHP code block near the TOP of your page */
// load viewer library
$libraryPath = 'cmsb/lib/viewer_functions.php';
$dirsToCheck = array('/home/sites/1a/b/b2c00d7c80/public_html/','','../','../../','../../../');
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 'fiat_models'
list($fiat_modelsRecords, $fiat_modelsMetaData) = getRecords(array(
'tableName' => 'fiat_models',
'where' => ' model_overview = "0" ', 
'loadUploads' => true,
'allowSearch' => true,

));

?>

By leo - April 26, 2018

Hi,

If that is your php code on the list page, $fiat_modelsRecords will be the variable you want to use. So the first record will be $fiat_modelsRecords[0].

Leo - PHP Programmer (in training)
interactivetools.com

By willydoit - April 26, 2018

Huge thanks Leo, that sorted it.