Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Foreach Support

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
devilzwishbone
Smarty n00b


Joined: 14 Jan 2014
Posts: 2

PostPosted: Tue Jan 14, 2014 10:14 pm    Post subject: Foreach Support Reply with quote

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
View user's profile Send private message
devilzwishbone
Smarty n00b


Joined: 14 Jan 2014
Posts: 2

PostPosted: Tue Jan 14, 2014 11:27 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP