View previous topic :: View next topic |
Author |
Message |
mrb Smarty n00b
Joined: 29 Jul 2004 Posts: 4
|
Posted: Thu Jul 29, 2004 7:36 pm Post subject: Sorry, i didn't find help section. Here's my question: |
|
|
Does smarty support operator in operator? 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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Jul 29, 2004 7:39 pm Post subject: |
|
|
$_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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jul 29, 2004 7:39 pm Post subject: |
|
|
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
{if $smarty.get.sub is not odd} // uses "is odd" syntax
...
{elseif $smarty.get.item == 'sapaliones'} // needs spaces
HTH |
|
Back to top |
|
mrb Smarty n00b
Joined: 29 Jul 2004 Posts: 4
|
Posted: Thu Jul 29, 2004 8:20 pm Post subject: |
|
|
That was just an example, i make spaces in real code 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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Thu Jul 29, 2004 8:24 pm Post subject: |
|
|
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 |
|
mrb Smarty n00b
Joined: 29 Jul 2004 Posts: 4
|
|
Back to top |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Fri Jul 30, 2004 2:16 pm Post subject: |
|
|
Use the debug console, be sure the values assigned in the template are what you're expecting. |
|
Back to top |
|
mrb Smarty n00b
Joined: 29 Jul 2004 Posts: 4
|
Posted: Fri Jul 30, 2004 8:31 pm Post subject: |
|
|
Damn, why i didn't think about that before? ) thx mohrt |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Fri Jul 30, 2004 11:45 pm Post subject: |
|
|
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 |
|
ivetter Smarty n00b
Joined: 27 Oct 2004 Posts: 1
|
Posted: Wed Oct 27, 2004 10:53 pm Post subject: |
|
|
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 |
|
mohrt Administrator
Joined: 16 Apr 2003 Posts: 7368 Location: Lincoln Nebraska, USA
|
Posted: Thu Oct 28, 2004 2:32 pm Post subject: |
|
|
That example is b0rken, I fixed it. |
|
Back to top |
|
|