Re: Re[2]: displaying data from database
| From: | Alexander Plakidin | Date: | Fri, 02 Nov 2001 21:40:57 +0000 |
| Subject: | Re: Re[2]: displaying data from database | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1825@lists.php.net to get a copy of this message | ||
Well, now I see that I have no alternatives to retrieving entire data which I need to be
displayed to an array of hash arrays.
I was just thinking if there is another way, like I did in FastTemplate - fetching data
row by row and adding rows to output. Somewhy I don't like fetching all data to memory at
once, I will perform some research of how can it reflect on performance.
Thanks,
Alex.
> Make sure you are only selecting the data necessary for the page. Or
> yes, you could make a custom function for doing pagination of some sort.
> Alexander Plakidin wrote:
>>
>> (Monte, sorry, I sent a message personally, now re-posting to this list for discussion)
>>
>> Do you mean loading all the data which is needed to be displayed into an array?
>> I'm against this approach... I think, it is too memory-consuming. Am I wrong?
>>
>> Your example is surely helpful, and I WAS using something like this, I'm only worried
>> if
>> it's effective!
>>
>> Alex.
>>
>> > Load them from the PHP script first, then call the template.
>> > $smarty = new Smarty;
>>
>> > $db_vars = get_db_vars();
>>
>> $smarty->>assign("dbvars",$dbvars);
>> $smarty->>display("index.tpl");
>>
>> > Alexander Plakidin wrote:
>> >>
>> >> Hi People,
>> >>
>> >> I'm new to Smarty (decided to migrate to Smarty from FastTemplate). Smarty
>> >> really looks
>> >> pretty cool, and I like it much more than FastTemplate. It seems to run much
>> >> faster (I
>> >> didn't do any tests, though), and provides alot of nice features.
>> >>
>> >> I am only wondering if I am using a right approach to display repeating data from
>> >> database. I was researching docs - they all say that data should be firstly
>> >> retrieved into
>> >> an array, and then displayed with FastTemplate. Pretty simple, yeah... I just
>> >> wonder if
>> >> this method is efficient enough - it is possible that a big amount of data will be
>> >> retrieved from database, and I am wondering if it can cause a slowdown. Can you,
>> >> guys,
>> >> tell me if I am wrong, and this approach is OK?
>> >>
>> >> I am currently using a scheme like this:
>> >>
>> >> {* firstly retrieve data from database *}
>> >> {* this will run a query and assign a variable which contains number of rows *}
>> >> {initiate_display}
>> >>
>> >> {section name=blabla loop=$numRows}
>> >> {* here I jump to next record, and retrieve current row to $RECORD array}
>> >> {next_record}
>> >>
>> >> {* and finally perform some output *}
>> >> {$RECORD.id}. {$RECORD.title}<br>
>> >> {/section}
>> >>
>> >> Actually, I don't like it as I have to write some custom functions, etc...
>> >> Please point me
>> >> to a right direction ;)
>> >>
>> >> Thanks,
>> >> Alex.