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

estou com problemas

 
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 -> Language: Portuguese
View previous topic :: View next topic  
Author Message
jamilservicos
Smarty n00b


Joined: 18 Mar 2008
Posts: 3

PostPosted: Tue Mar 18, 2008 6:56 am    Post subject: estou com problemas Reply with quote

sei que a solução esta na minha frente, mas não consigo ver...

o problema é o seguinte tenho 2 tabelas mysql, que são montadas em php, atraves de um implode. já migrei todo o script para smarty e jah obtenho resultado em tpl...

mas a tabela esta desloca...

no sql possuo uma tabela de categoria cujo possui (id, catname) e a outra tabela tem o conteudo das categorias onde tem (id, members, description, bold, highlight, outside, categories)

atualmente possuo 8 categorias e 5 desciptions.

montei assim:



<table width="80%" align="center">
{section name=catname loop=$catname}

<tr>
<th class="top" width="61%">
<b> {$catname[catname]} </b>
</th>
<th class="top" width="13%">
<div align="center">
<b>Members</b></div>
</th>
<th class="top" width="13%">
<div align="center">
<b>Outside</b></div>
</th>
<th class="top" width="13%">
<div align="center">
<b>Total</b></div>
</th>
</tr>
{section name=links loop=$rowr_id}
<tr>
<td width="61%" bgcolor="{$highlight[links]}">
{$bold[links]}<a href="viewp.php?ad={$rowr_id[links]}" target="_blank">{$rowr_description[links]}</a>{$boldc[links]}
</td>
<td width="13%" bgcolor="{$highlight[links]}">
{$rowr_members[links]}
</td>
<td width="13%" bgcolor="{$highlight[links]}">
{$rowr_outside[links]}
</td>
<td width="13%" bgcolor="{$highlight[links]}">
{$rowr_total[links]}
</td>
</td>

{/section}

{/section}


mas repete todas as descriptions dentro de cada categoia, ao inves de mostrar as descriptions em suas devidas categorias...

Exemplo:

categoriaA
Description(categoriesA)

categoriaB
Description(categoriesB)

Ao inves disso aparece:

categoriaA
Description(categoriesA)
Description(categoriesB)

categoriaA
Description(categoriesA)
Description(categoriesB)

espero que tenham entendido!


O codigo original no php que junta as tabelas é:

$template = implode("", file("titulosp.php"));

mostrarTemplate($template, $row);

onde $row eh a função que puxa os dados do mysql

e o titulosp.php contem:

<tr>
<td width="61%" bgcolor="<?=$highlight?>">
<?=$bold?><a href="viewp.php?ad=<?=$id?>" target="_blank"><?=$description?></a><?=$boldc?>
</td>
<td width="13%" bgcolor="<?=$highlight?>">
<?=$members?>
</td>
<td width="13%" bgcolor="<?=$highlight?>">
<?=$outside?>
</td>
<td width="13%" bgcolor="<?=$highlight?>">
<?=$total?>
</td>
</td>


a função mostrarTemplate contem:

function mostrarTemplate($tema, $variables)
{
//var_dump($variables);
extract($variables);
eval("}".$tema."{");
}


preciso de uma solução para substituir esse implode para fazer minhas tabelas com o smarty!

Att.
Back to top
View user's profile Send private message
migas
Smarty Regular


Joined: 07 Apr 2004
Posts: 73
Location: Porto, Portugal

PostPosted: Fri Mar 28, 2008 3:02 pm    Post subject: Reply with quote

Peço desculpa se estou a dizer uma estupidez.


Testa uma coisa semelhante
PHP
Code:

$sql ="SELECT * FROM
tabela_1, tabela_2
WHERE
tabela_1_relacao = tabela_2_relacao ";

$resultados_em_array = funcao_retorna_array($sql);
$smarty->assign("resultados", $resultados_em_array);


SMARTY
Code:

<table>
{section name="sec" loop=$resultados}
   {if $resultados[sec.index_prev].tabela_1_relacao != $resultados[sec].tabela_1_relacao}
      <tr>
         <td colspan="2">{$resultados[sec].tabela_1_relacao}</td>
      </tr>
   {/if}
<tr>
   <td>{$resultados[sec].tabela_1_info_qq}</td>
   <td>{$resultados[sec].tabela_1_info_qq2}</td>
</tr>
{/section}
</table>
Back to top
View user's profile Send private message
jamilservicos
Smarty n00b


Joined: 18 Mar 2008
Posts: 3

PostPosted: Sat Mar 29, 2008 2:27 pm    Post subject: Reply with quote

$resultados_em_array = funcao_retorna_array($sql);

qual seria a funcao_retorna_array?
Back to top
View user's profile Send private message
migas
Smarty Regular


Joined: 07 Apr 2004
Posts: 73
Location: Porto, Portugal

PostPosted: Tue Apr 08, 2008 10:07 am    Post subject: Reply with quote

jamilservicos wrote:
$resultados_em_array = funcao_retorna_array($sql);

qual seria a funcao_retorna_array?


Esta função poderá ser feita por ti de modo a facilitar a interacção entre o php e o smarty.

Por exemplo:
Code:

function funcao_retorna_array($query)
{
   $resultado = mysql_query($query);
   while ($linha = mysql_fetch_array($resultado))
   {
      $retorna[]=$linha;
   }
   
   return $retorna;
}


Desta forma vais ter um array com a seguinte estrutura

Code:

#Linha 1
$resultados_em_array[0][campo1] = "valor1";
$resultados_em_array[0][campo2] = "valor2";
#Linha 2
$resultados_em_array[1][campo1] = "valor3";
$resultados_em_array[1][campo2] = "valor4";
print_r($resultados_em_array);

Array
(
    [0] => Array
        (
            [campo1] => valor1
            [campo2] => valor2
        )

    [1] => Array
        (
            [campo1] => valor3
            [campo2] => valor4
        )

)
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 -> Language: Portuguese 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