View previous topic :: View next topic |
Author |
Message |
carlosvictorica Smarty Rookie
Joined: 30 Jan 2004 Posts: 13 Location: Salamanca, Guanajuato, México
|
Posted: Fri Jan 30, 2004 5:38 pm Post subject: solve section trouble ... |
|
|
Hi, i can't get to display the entire array with section loop, It only appears the first two elements.
here is my code :
//This is my multidimensional array , i hope this won't produce an error
// with {section}
$part_arr = array("clv" => array(),"partida" => array());
// Then i put the result of query on the array, with array_push
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC)){
array_push($part_arr["clv"],$row['ClvPartida']);
array_push($part_arr["partida"],$row['Partida']);
}
// Finally assign the array to the smarty variable
$smarty->assign('part_arr',$part_arr);
$smarty->display('partidas.html');
HERE IS MY TEMPLATE :
{if $mod == "search"}
<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr class="tinyTitle">
<td width="10%" class="tinyTitle">Partida</td>
<td width="90%" class="tinyTitle">Descripción</td>
</tr>
// THIS IS THE IMPORTANT PART
{section name=row loop=$part_arr}
<tr bgcolor="{cycle values="#1C89B3,#BA5625"}">
<td class="tiny">{$part_arr.clv[row]}</td>
<td class="tiny">{$part_arr.partida[row]}</td>
</tr>
{/section}
</table>
//END OF TEMPLATE
It's weird that it cannot display all the items of the array. Besides i have another identical script to this and it works fine. _________________ Don't wash your dirty underwear in public |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Jan 30, 2004 7:32 pm Post subject: |
|
|
you array has just two elements: with the keys "clv" and "partida", maybe you want to loop over $part_arr.clv instead of $part_arr ? |
|
Back to top |
|
carlosvictorica Smarty Rookie
Joined: 30 Jan 2004 Posts: 13 Location: Salamanca, Guanajuato, México
|
Posted: Fri Jan 30, 2004 7:58 pm Post subject: |
|
|
No, $part_arr is 2D array :
clv => Array (7)
0 => 2101
1 => 2102
2 => 2103
3 => 2105
4 => 2106
5 => 2107
6 => 2207
partida => Array (7)
0 => Part1
1 => Part2
2 => Part3
3 => Part4
4 => Part5
5 => Part6
6 => Part7
and what i want to do is this :
<tr bgcolor="#1C89B3">
<td class="tiny">2101</td>
<td class="tiny">Part1</td>
</tr>
<tr bgcolor="#BA5625">
<td class="tiny">2102</td>
<td class="tiny">Part2</td>
</tr>
... UNTIL
<tr bgcolor="#BA5625">
<td class="tiny">2207</td>
<td class="tiny">Part7</td>
</tr>
I said it's weird because it only displays the first two rows , instead of the entire rowset. _________________ Don't wash your dirty underwear in public |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Fri Jan 30, 2004 8:02 pm Post subject: |
|
|
smarty looks only at the first dimension and finds two entries. so it loops from 0..1. |
|
Back to top |
|
carlosvictorica Smarty Rookie
Joined: 30 Jan 2004 Posts: 13 Location: Salamanca, Guanajuato, México
|
Posted: Fri Jan 30, 2004 8:09 pm Post subject: |
|
|
But i have another script that does the same thing and works perfectly. Hence i'm looking to use foreach but i can't get to display correctly in my table.
Is there any other way, or i may say the BEST way to display data in a table without using html_table ... ?
Thanks for your help messju. _________________ Don't wash your dirty underwear in public |
|
Back to top |
|
carlosvictorica Smarty Rookie
Joined: 30 Jan 2004 Posts: 13 Location: Salamanca, Guanajuato, México
|
Posted: Fri Jan 30, 2004 8:10 pm Post subject: |
|
|
But i have another script that does the same thing and works perfectly. Hence i'm looking to use foreach but i can't get to display correctly in my table.
Is there any other way, or i may say the BEST way to display data in a table without using html_table ... ?
Thanks for your help messju. _________________ Don't wash your dirty underwear in public |
|
Back to top |
|
carlosvictorica Smarty Rookie
Joined: 30 Jan 2004 Posts: 13 Location: Salamanca, Guanajuato, México
|
Posted: Fri Jan 30, 2004 8:26 pm Post subject: |
|
|
Sorry, i have solved my problem here but i found it strange , i have to check this later :
this is my template that works fine:
Code: |
{section name=row loop=$regprv}
<tr bgcolor="{cycle values="#1C89B3,#BA5625"}">
<td class="tiny">{$regprv.razonsocial[row]}</td>
<td class="tiny">{$regprv.rfc[row]}</td>
<td class="tiny">{$regprv.dir[row]}</td>
<td class="tiny">{$regprv.tel[row]}</td> <td class="tiny">{$regprv.ciudad[row]}</td>
<td class="tiny">{$regprv.estado[row]}</td>
<td class="tiny">{$regprv.email[row]}</td>
</tr>
{/section}
|
and I was doing the same to this , only that i used $part_arr.clv
and it worked fine ...
Code: |
{section name=row loop=$part_arr.clv}
<tr bgcolor="{cycle values="#1C89B3,#BA5625"}">
<td class="tiny">{$part_arr.clv[row]}</td>
<td class="tiny">{$part_arr.partida[row]}</td>
</tr>
{/section}
|
So what was the problem ?? _________________ Don't wash your dirty underwear in public |
|
Back to top |
|
|