simple variable issue (hopefully)

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

By willydoit - April 25, 2018

Hi all,

I am creating a page to display different models and sub models of vehicles most of which works but I have run into a slight issue in that I can display a listing page of sub models but I want to use one of the variables ie "model" as a part of the page title  ie

listing of the variants of the  <?php echo htmlencode($record['model']) ?>

I  have a foreach model routine to create the list.  However because my use of the variable in the title comes before my foreach statement to produce the list I get an unknown variable error. My question is, is there a simple way to take the "model" value just from the first record and use it before the main foreach statement used to produce the listing.

My assumption is that I would have to create a separate for each loop prior to the main listings which would

a) create a counter, set at 0

b) take the "model" value from just the first record, and display it in the page title <?php echo htmlencode($record['model']) ?>

c) add to the counter to equal 1

d) create a routine to exit the for each loop if the counter = 1

e) proceed to the next foreach loop for the listings section with <?php foreach ($fiat_modelsRecords as $record): ?>

Unfortunately I am not a programmer so am not sure whether

a) my idea would work

b) whether using the first record for the title would in any way affect its ability to be contained in the main listing and

c) if it can be done how best to implement it.

Any help/advice would be gratefully appreciated.

Thanks in advance.

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 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.