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

Sorry, i didn't find help section. Here's my question:

 
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 -> Tips and Tricks
View previous topic :: View next topic  
Author Message
mrb
Smarty n00b


Joined: 29 Jul 2004
Posts: 4

PostPosted: Thu Jul 29, 2004 7:36 pm    Post subject: Sorry, i didn't find help section. Here's my question: Reply with quote

Does smarty support operator in operator? Smile i mean can i do this:

{if $_GET[sub]!=odd}
hello
{if $_GET[num]!=odd}
bonjour
{else}
salut
{/if}
{elseif $_GET[item]=='sapaliones'}
sapaliojam
{else}
goodbye
{/if}

i'm making my site and i having problems at this point so i thought maybe smarty doesn't support this?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Jul 29, 2004 7:39 pm    Post subject: Reply with quote

$_GET[sub] probably isn't what you want.

try:

{$smarty.get.sub}

or:

$smarty->assign_by_ref($_GET,'_GET');

then:

{$_GET.sub}


Last edited by mohrt on Thu Jul 29, 2004 7:40 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jul 29, 2004 7:39 pm    Post subject: Reply with quote

This is covered in the manual: http://smarty.php.net/manual/en/language.function.if.php

1) you need spaces
2) there is a syntax when using "odd"
3) plus mohrt's comments Smile

{if $smarty.get.sub is not odd} // uses "is odd" syntax
...
{elseif $smarty.get.item == 'sapaliones'} // needs spaces

HTH
Back to top
View user's profile Send private message
mrb
Smarty n00b


Joined: 29 Jul 2004
Posts: 4

PostPosted: Thu Jul 29, 2004 8:20 pm    Post subject: Reply with quote

That was just an example, i make spaces in real code Wink Maybe i'll sound very lame, but can you help me with this:

// some pages with sub outputs fine, but others don't.
// i don't know everything seems ok to me, couse
// in database i have everything needed

index.php:
$reskoment=mysql_query("SELECT * FROM gbook WHERE id='{$_GET['sub']}' ORDER BY gbptime DESC"); // querry is ok 100%
$num = mysql_num_rows($reskoment);
while ($row2=mysql_fetch_array($reskoment)) {
$gbtime[] .= $row2[gbptime];
$gbnick[] .= $row2[gbvardas];
$gbcmmnt[] .= $row2[gbkoment];
}
$smarty->assign("gbtime",$gbtime);
$smarty->assign("gbnick",$gbnick);
$smarty->assign("gbcmmnt",$gbcmmnt);
$smarty->display('index.tpl');

index.tpl:
{section name=nr loop=$gbnick}
<table width=100% border=0 cellspacing=0 cellpadding=5><tr><td class=tbl2><font size=2><b>{$gbnick[nr]} rašo:</b></font><br><font size=1 color=#333333>{$gbtime[nr]}</font><br><br>{$gbcmmnt[nr]}</td></tr></table><br>
{/section}
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Thu Jul 29, 2004 8:24 pm    Post subject: Reply with quote

I didn't look closely, but I bet your problem are the lines like:

$gbtime[] .= $row2[gbptime];

I would think you would want:

$gbtime[] = $row2[gbptime];
Back to top
View user's profile Send private message
mrb
Smarty n00b


Joined: 29 Jul 2004
Posts: 4

PostPosted: Fri Jul 30, 2004 9:56 am    Post subject: Reply with quote

I'll try, but http://smarty.php.net/contribs/examples/mysql/mysql.phps says to write like i did Smile
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Fri Jul 30, 2004 2:16 pm    Post subject: Reply with quote

Use the debug console, be sure the values assigned in the template are what you're expecting.
Back to top
View user's profile Send private message Visit poster's website
mrb
Smarty n00b


Joined: 29 Jul 2004
Posts: 4

PostPosted: Fri Jul 30, 2004 8:31 pm    Post subject: Reply with quote

Damn, why i didn't think about that before? Smile) thx mohrt
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Fri Jul 30, 2004 11:45 pm    Post subject: Reply with quote

mrb wrote:
I'll try, but http://smarty.php.net/contribs/examples/mysql/mysql.phps says to write like i did Smile


That just looks wrong to me, though it might not be different in practice.

The thing is: $foo[] appends a new array element to $foo. SImilarly, $bar .= $foobar appends the string $foobar to the string $bar. Thus, $foo[] .= $bar appends the string bar to the string in the new array element $foo[]. EXCEPT, that $foo[] is necessarily null prior to having $bar appended. PHP probably makes this work, but it is weird city if you ask me.
Back to top
View user's profile Send private message
ivetter
Smarty n00b


Joined: 27 Oct 2004
Posts: 1

PostPosted: Wed Oct 27, 2004 10:53 pm    Post subject: Reply with quote

Hey mrb,

This sql:

"SELECT * FROM gbook
WHERE id='{$_GET['sub']}'
ORDER BY gbptime DESC"

is a really bad idea.

Someone could make sub: ';delete from gbook;select * from gbook where sub = 'foo

Isaac Vetter
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Thu Oct 28, 2004 2:32 pm    Post subject: Reply with quote

mrb wrote:
I'll try, but http://smarty.php.net/contribs/examples/mysql/mysql.phps says to write like i did Smile


That example is b0rken, I fixed it.
Back to top
View user's profile Send private message Visit poster's website
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 -> Tips and Tricks 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