Using List Section Editor FOREACH to assign variables for printed output outside of the actual FOREACH statement
3 posts by 2 authors in: Forums > CMS Builder
Last Post: April 14, 2011 (RSS)
By Steve99 - April 12, 2011
Hello. Here is my situation:
From the output of a List Section Editors Code Generator - I would like to manipulate and use the FOREACH function to assign variables to each row WITHOUT immediate printed output...
So instead of having it loop through the FOREACH statement and output each row using the $record variable, I want to be able to assign a variable for use later in the page.
The page itself is for boat docking slip assignments. I have a designed table to give people a visual representation of the docks from an overhead view. I would like to use the variables to fill out this matrix.
My thought was to set $i equal to zero before the FOREACH function, then inside the FOREACH function to have $i++ added to the outputted variables.
(example: $dockNumber1 $personsLastName1, $dockNumber2 $personsLastName2, $dockNumber3 $personsLastName3, etc. )
Please let me know if further clarification is needed.
Thank you in advance!
From the output of a List Section Editors Code Generator - I would like to manipulate and use the FOREACH function to assign variables to each row WITHOUT immediate printed output...
So instead of having it loop through the FOREACH statement and output each row using the $record variable, I want to be able to assign a variable for use later in the page.
The page itself is for boat docking slip assignments. I have a designed table to give people a visual representation of the docks from an overhead view. I would like to use the variables to fill out this matrix.
My thought was to set $i equal to zero before the FOREACH function, then inside the FOREACH function to have $i++ added to the outputted variables.
(example: $dockNumber1 $personsLastName1, $dockNumber2 $personsLastName2, $dockNumber3 $personsLastName3, etc. )
Please let me know if further clarification is needed.
Thank you in advance!
Re: [steve99] Using List Section Editor FOREACH to assign variables for printed output outside of the actual FOREACH statement
By robin - April 13, 2011
Hey Steve,
I would recommend using arrays for this problem. It is a lot easier to deal with once it's set up. Keep the $i++ in the foreach loop, but assign the variables like this:
Then when you're ready to display, for example, dockNumber 2 you can use this:
Hope that helps,
Robin
I would recommend using arrays for this problem. It is a lot easier to deal with once it's set up. Keep the $i++ in the foreach loop, but assign the variables like this:
$dockNumber[$i] = $record['dockNumber'] //Or whatever you've named the record/column.
$personsLastName[$i] = $recocrd['personsLastName']
Then when you're ready to display, for example, dockNumber 2 you can use this:
echo $dockNumber[2];
Hope that helps,
Robin
Robin
Programmer
interactivetools.com
Programmer
interactivetools.com
Re: [robin] Using List Section Editor FOREACH to assign variables for printed output outside of the actual FOREACH statement
By Steve99 - April 14, 2011
Great, thank you for your correspondence. It ended up being as easy as I thought it would be. I used the standard list load record output in combination with my basic foreach statement.
Plugged in the vars where they needed to be in the docks overhead view and that was it. Simple.
P.S. I love this product! Saves me so much development time!
list($dock_assignmentsRecords, $dock_assignmentsMetaData) = getRecords(array(
'tableName' => 'dock_assignments',
));
$i = 0;
foreach ($dock_assignmentsRecords as $record) {
$title[$i] = $record['title'];
$i++;
}
Plugged in the vars where they needed to be in the docks overhead view and that was it. Simple.
P.S. I love this product! Saves me so much development time!