|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
Konstantin555 Smarty n00b
Joined: 01 Nov 2010 Posts: 2
|
Posted: Mon Nov 01, 2010 10:54 am Post subject: How to divide code, using the output from the database? |
|
|
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 |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Mon Nov 01, 2010 1:36 pm Post subject: |
|
|
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 |
|
Konstantin555 Smarty n00b
Joined: 01 Nov 2010 Posts: 2
|
Posted: Mon Nov 01, 2010 5:34 pm Post subject: |
|
|
Oh! Thank you very much! This is what I need |
|
Back to top |
|
|
|
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
|