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

Simple Array Loop

 
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
Reformed
Smarty Rookie


Joined: 16 Jul 2003
Posts: 24

PostPosted: Wed Jul 16, 2003 1:58 am    Post subject: Simple Array Loop Reply with quote

I'm very sorry if this question has bee asked before, but I did spend a considerable amount of time searching and reading things that almost explained how to solve my problem, but didn't quite get it.

All I want to know is how to do a for each, looping through an array of a database recordset in a formatted table. In php it's no problem, I just set up a do while or a for each statement, insert my array with the associative indexes in their proper locations and that's it.

All I want to do is that very thing using Smarty, but I can't find a decent explaination on how this is done, and so, I ask the experts. Here is what I'm working with and it is failing:

Code:
{ *create a smarty section to output the data in the array. alternate colors* }
      { section name=info loop=$outPut }
        <tr bgcolor="{ cycle values="#FFFFFF, #EFEFEF" }">
          <td align="left" valign="top"><img src="{#imageDir#}dot_clr.gif" width="10" height="25"></td>
          <td align="left" valign="middle" class="tableText">{$outPut[info].day}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td align="right" valign="middle" class="tableText">{$outPut[info].hours_worked}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].short_desc}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].client}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].project}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].category}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].billable}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].rush}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].invoice_num}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td valign="middle" class="tableText">{$outPut[info].employee}</td>
          <td><img src="{#imageDir#}dot_clr.gif" width="10"></td>
          <td><input name="edit" type="checkbox" id="edit" value="checkbox"></td>
          <td>&</td>
        </tr>
        { /section }


Please let me know if this is unclear.
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 8:47 am    Post subject: Reply with quote

Hi Reformed.

You might find it easier to use {foreach} instead of {section}.

A simplified version of your example would be:

Code:

{foreach from=$outPut item=info}
  <tr>
    <td>{$info.day}</td>
  </tr>
{/foreach}


Is that what you are after? There is also a manual page available.

Good Luck!
Back to top
View user's profile Send private message
Reformed
Smarty Rookie


Joined: 16 Jul 2003
Posts: 24

PostPosted: Wed Jul 16, 2003 4:14 pm    Post subject: Reply with quote

Thank you for the help. Simple. Bye the way, is there a story behind your avatar?
Back to top
View user's profile Send private message Send e-mail
Reformed
Smarty Rookie


Joined: 16 Jul 2003
Posts: 24

PostPosted: Wed Jul 16, 2003 5:15 pm    Post subject: Reply with quote

Well, I tried what you said and I'm getting output now, it's just all numbers though. Is there something more that I need to do?
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 6:56 pm    Post subject: Reply with quote

You will have to post some of your PHP code that is generating the array $outPut array and/or provide a print_r($outPut). Also provide some of the final template results.

As for the Avatar... well, when I saw the original picture of these 3 cats I was struck by it and worked it into what you see now, appropriately called "Alien Cats". That may or may not be the full and/or true story.... but thanks for asking!
Back to top
View user's profile Send private message
Reformed
Smarty Rookie


Joined: 16 Jul 2003
Posts: 24

PostPosted: Wed Jul 16, 2003 7:06 pm    Post subject: Reply with quote

Well, it turns out that you where right (I didn't doubt you of course) in your first response to my query. My problem turned out to be a PEAR DB issue instead. I think I'm trying to learn to many classes at once.

I must say that I thought the avatar was 3 chihuahuas. Very Happy
Back to top
View user's profile Send private message Send e-mail
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Wed Jul 16, 2003 7:12 pm    Post subject: Reply with quote

@Reformed: Keep at it! I often think that the hardest part of learning something new (let alone a chain of something news) is knowing where to look for errors.

DOGS you say! No, these are alien cats with their tinfoil caps removed.
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