|
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 |
ronsen Smarty Rookie
Joined: 07 Jun 2003 Posts: 13 Location: Baden/Wien Austria
|
Posted: Sat Jun 07, 2003 7:55 pm Post subject: formating output a table/tr/td/td in a loop |
|
|
Hi,
can any of you help me with my problem please.
I read data from a db into a array with smarty and try to fillin in a table with 2 row and 2 col each row the output shout be look like
Titel1 | Titel2
Text1 | Text2
I guess the script fills only one col in a loop
I thought to run 2 loops if possible one with odd and one with even??
or to I have to make a new templat and create a second table?
in this code I get all data but the output looks like
Titel
Text
TIA
Ron
Code: |
<table width="100%" height="0" border="0" align="center" cellpadding=4 cellspacing=5 div id="tablemess">
{section name=nr loop=$results}
<tr >
{if $smarty.section.nr.iteration is odd}
<td width="30%"><div id="Titel">{$results[nr].news_titel}</div></th>
{else}
<td width="30%"><div id="Titel">{$results[nr].news_titel}</div></td>
{/if}
</tr>
<tr>
{if $smarty.section.nr.iteration is odd}
<td width="30%">{$results[nr].news_text}</div></th>
{else}
<td width="30%">{$results[nr].news_text}</div></td>
{/if}
</tr>
{/section}
</table>
| [/code] |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Jun 08, 2003 1:58 am Post subject: |
|
|
Hi ronsen -- I'm not sure I can see what you are trying to do. Can you post a sample of your $results array?
I almost think you want something like this:
Code: | <table width="100%" height="0" border="0" align="center" cellpadding=4 cellspacing=5 div id="tablemess">
{section name=row loop=$results}
<tr>
{foreach from=$results[row] key=col item=data}
<td width="30%"><div id="{$col}">{$data}</div></td>
{/foreach}
</tr>
{/section}
</table> |
?? |
|
Back to top |
|
ronsen Smarty Rookie
Joined: 07 Jun 2003 Posts: 13 Location: Baden/Wien Austria
|
Posted: Sun Jun 08, 2003 11:16 am Post subject: |
|
|
Hi boots,
I find out the answer to my problem is pulling in the data of db.
now I run this script
Code: |
$i=0;
while ($r=mysql_fetch_array($res)) {
$tmp = array(
"news_titel_0" => $r["titel"], // read title
"news_text_0" => $r["text"] // read text
);
$results[$i++] = $tmp; // add to results
}
|
the $results looks like
Array ( [0] => Array ( [news_titel_0] => title1 [news_text_0] => text1) [1] => Array ( [news_titel_0] => title2 [news_text_0] => text2........)
but I need
Array ( [0] => Array ( [news_titel_0] => title1 [news_titel_0] => title2) [1] => Array ( [news_text_0] => text1 [news_text_0] => text2........)
so I have to figure out how to build the script to get to this output
thank you
Ron |
|
Back to top |
|
gurdji Smarty n00b
Joined: 22 Jun 2010 Posts: 3
|
Posted: Sat Dec 25, 2010 8:54 am Post subject: |
|
|
Hello
I want to display results from database in 2 columns I dind't masnage to do this
col1 col2
----------------------------------
Afghanistan Andorra
Australia Barbados
Belgium Brunei
my php code is this
$query = "Select country.country_id As id,
country.country_name As country,
country.code As code,
country.show_aupairs As show_aupairs,
country.show_families As show_families,
country.*
From country
Where country.show_aupairs = 'Y'";
$result=mysql_query($query);
$contor=0;
while($row=mysql_fetch_array($result)){
$families_from[$contor][id] = $row['id'];
$families_from[$contor][country] = $row['country'];
$families_from[$contor][show_aupairs] = $row['show_aupairs'];
$families_from[$contor][show_families] = $row['show_families'];
$contor++;
}
//-
$smarty->assign("families_from",$families_from);
thnk you |
|
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
|