View previous topic :: View next topic |
Author |
Message |
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Thu Mar 14, 2013 6:26 pm Post subject: how to show the contents of a session? |
|
|
Hi
how to show the contents of a session? I have the $ _SESSION [alert], how to show the content in the tpl file?
Thanks |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
|
Back to top |
|
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Thu Mar 14, 2013 8:05 pm Post subject: |
|
|
Hi,
thanks.
{$smarty.session.minhalista}
show only
Array
why?
I want to show what is in $ _SESSIO [minhalista]
Quote: | echo "id". $ row ['business_id']. "|". "name". $ row ['BUSINESS_NAME']. "<a href = '#' class = 'del' rel = '". $ id."' nm = '". $ name."'> dEL FAVORITES </ a> <br /> "; |
in php show,
Quote: | id: 564 | nome: vende-se celta muito barato. preço de oportunidade. confira DEL FAVORITOS
id: 566 | nome: Palio 2009/2010 DEL FAVORITOS
id: 565 | nome: Celta vermelho, 2 portas, usado. DEL FAVORITOS
id: 568 | nome: Celta vermelho, 2 portas, usado. DEL FAVORITOS
id: 567 | nome: vende-se celta muito barato. preço de oportunidade. confira DEL FAVORITOS |
in tpl not
Thanks for help[/quote] |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 14, 2013 8:23 pm Post subject: |
|
|
It must be an array of values?
{$smarty.session.minhalista.0}
will show the first one. Or you can loop with foreach. |
|
Back to top |
|
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Thu Mar 14, 2013 8:33 pm Post subject: |
|
|
Hi,
thanks
show me an example, please, have tried everything and nothing works.
Thanks again |
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 14, 2013 8:38 pm Post subject: |
|
|
Code: | {foreach $smarty.session.minhalista as $s}
{$s}
{/foreach} |
(this is Smarty 3 syntax) |
|
Back to top |
|
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Thu Mar 14, 2013 8:52 pm Post subject: |
|
|
Thanks.
with this example gives error in the TPL
what might be happening? I really need it.
see
in php
Quote: | if ($_SESSION && $_SESSION['minhalista'] != null){
foreach($_SESSION['minhalista'] as $key => $value)
{
$id = $_SESSION['minhalista'][$key];
$sel = mysql_query("SELECT * FROM classificados WHERE business_id = '".$id."'");
while($row = mysql_fetch_array($sel)){
echo "id: ".$row['business_id']." | "."nome: ".$row['business_name']." <a href='#' class='del' rel='".$id."' nm='".$nome."'>DEL FAVORITOS</a><br /> ";
}
}
} |
in TPL
Quote: | {foreach $smarty.session.minhalista as $s}
{$s}
{/foreach} |
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Mar 14, 2013 8:58 pm Post subject: |
|
|
You are selecting data from the database inside the loop. You don't want to do that in Smarty, do that in PHP.
In php in the while loop, instead of echoing push the contents to an array, then assign the array to smarty and loop over the array in the template.
Something like:
PHP:
Code: | while($row = mysql_fetch_array($sel)){
$rows[] = $row;
}
$smarty->assign('rows',$rows); |
Smarty:
Code: | {foreach $rows as $row}
{$row.id} | {$row.business_name} (etc)
{/foreach} |
|
|
Back to top |
|
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Fri Mar 15, 2013 2:12 am Post subject: |
|
|
hi.
worked!! thank you very much |
|
Back to top |
|
terra Smarty Rookie
Joined: 27 Jul 2011 Posts: 26
|
Posted: Fri Mar 15, 2013 6:55 pm Post subject: |
|
|
Hi,
how do I call the TPL file?
if( isset( $_SESSION["minhalista"][$id]) == $id ){
Thanks |
|
Back to top |
|
|