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

How to divide code, using the output from the database?

 
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
Konstantin555
Smarty n00b


Joined: 01 Nov 2010
Posts: 2

PostPosted: Mon Nov 01, 2010 10:54 am    Post subject: How to divide code, using the output from the database? Reply with quote

Good afternoon! Can you help me with one question - how to divide code, using the output from the database?
For example, I need to fill the table. PHP code is

Code:
...
$output = "<table>\n";

while ($row = mysql_fetch_array($result)) {
   $output.="<tr><td>".$row['Name']."</td><td>".$row['Surname']."</td></tr>\n";
}
$output.= "</table>\n";
$smarty->assign("output_data",$output);
...


In future, design can be change and instead of a table will be used divs, for example.. And in this case I need to rewrite php output code... That's why I need to write more generalized code. How to do this?..

And now in the php-file using both code and design together... that is not correct...

Thank you before!
And sorry for any my mistakes I am from Ukraine Smile
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Mon Nov 01, 2010 1:36 pm    Post subject: Reply with quote

Code:
while ($row = mysql_fetch_array($result)) {
   $rows[] = $row;
}
$smarty->assign("rows",$rows);


template:

Code:
{foreach from=$rows item="row"}
   <div class="row">
        <span class="rowName">{$row.Name}</span>
        <span class="rowSurname">{$row.Surname}</span>
    </div>
{/foreach}


or however you want to mark it up...
Back to top
View user's profile Send private message Visit poster's website
Konstantin555
Smarty n00b


Joined: 01 Nov 2010
Posts: 2

PostPosted: Mon Nov 01, 2010 5:34 pm    Post subject: Reply with quote

Oh! Thank you very much! This is what I need Exclamation
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