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

Doubble loop to one to increase perfomace

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
infira
Smarty n00b


Joined: 28 Oct 2011
Posts: 2

PostPosted: Tue Nov 01, 2011 8:54 am    Post subject: Doubble loop to one to increase perfomace Reply with quote

Old way
Prepare data in php
Code:
<?php
class myClass
{
   public function parseData($assignName,$ID)
   {
      $data = dbQuery("SELECT * FROM articles ID = $ID");
      $list = array();
      if (is_resource($data))
      {
         while ($Row = mysql_fetch_object($data))
         {
            $Row->link = fixLink($Row->link);
            // do some more cool stuff here
            
            $list[] = $Row;
         }
      }
      $smarty->assign($assignName,$list);
   }
}
$class = new myClass();
$smarty->assign("MyClass",$class);
?>

And in the template file i do this
Code:
{$MyClass->setData("parsedData",41)}
{foreach from = $parsedData item = row}
   {$row->link}
{/foreach}


If i have a large amount of data in this way data is looped twise.
how do decrease foreach to one.
Perhaps something like this
Code:
{data ID = 41 item = row}
   {$row->link}
{/data}


And in the block is compiled smarty tempalte source and data in the same time, is it possible
Back to top
View user's profile Send private message
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Tue Nov 01, 2011 12:34 pm    Post subject: Reply with quote

See http://www.smarty.net/docs/en/language.function.foreach.tpl example 7.33 how you can loop directly over search results by using PDO.
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 -> Smarty Development 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