|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
devilzwishbone Smarty n00b
Joined: 14 Jan 2014 Posts: 2
|
Posted: Tue Jan 14, 2014 10:14 pm Post subject: Foreach Support |
|
|
Background:
Im running a script on a custom CRM system im developing
The system has been programmed to have infinite number of campaigns
with an infinite number of questions and therefore needed to store an infinite number of answers
Problem with MySQL is you have to pre-set the tables to store data on or program it in PHP and you would have a lot of empty fields depending on the volume of questions per campaign.
So thats the background as to why my system isnt quite straight forward as most databases where the values always remain the same.
The problem
So what is my Foreach problem I hear you ask?
Im reading questions from lets say the Questions Table
Im reading the answers from lets say the Answers table
When im trying to populate the information on the template
I run into a problem
I cannot have
Code: |
<table>
<tr><td>Question</td><td>Answer</td></tr>
{foreach $Questions as $Q}
{foreach $answers as $A}
<tr><td>{$Q.Question}</td></tr>
<tr><td>{$A.Answer}</td></td>
{/foreach}
{/foreach}
</table>
|
PS its gathered data via PDO not the usual Array format in the PHP file.
So how can I get it so that I can run 2 foreach simultaneously from different data sources?[/code] |
|
Back to top |
|
devilzwishbone Smarty n00b
Joined: 14 Jan 2014 Posts: 2
|
Posted: Tue Jan 14, 2014 11:27 pm Post subject: |
|
|
Resolved it...
Solution
2 Foreach commands
except the second contains a break command
Simplified version
Code: |
{foreach $Questions as $i}
{$i.Question}
{foreach $Answers as $a}
{$a.Answer}
{break}
{/foreach}
{/foreach}
|
Whilst I manage to find the solution out for my self I still shared it incase any one else comes across the same issue in the future |
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|