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

if with stristr case

 
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 -> General
View previous topic :: View next topic  
Author Message
mozolici
Smarty Rookie


Joined: 18 Aug 2007
Posts: 21
Location: Suceava / Romania

PostPosted: Tue May 26, 2009 1:02 pm    Post subject: if with stristr case Reply with quote

how to modify this code in tpl format?

Code:
<?php
  $string = 'Hello World!';
  if(stristr($string, 'earth') === FALSE) {
    echo '"earth" not found in string';
  }
// outputs: "earth" not found in string
?>



i try to use this but dosent work

Code:
{if (stristr($string, 'earth') === FALSE)}
"earth" not found in string'
{/if}

_________________
be fiRst but fiRst think fiRst!
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Tue May 26, 2009 1:11 pm    Post subject: Reply with quote

Try this:

Code:
{if $string|stristr:"earth"}
  earth found
{else}
  earth not found
{/if}
Back to top
View user's profile Send private message Visit poster's website
mozolici
Smarty Rookie


Joined: 18 Aug 2007
Posts: 21
Location: Suceava / Romania

PostPosted: Tue May 26, 2009 6:10 pm    Post subject: Reply with quote

thanks for first code

i need some .... more help

i have this php code

Code:
$categ = array(10=>"apple",245=>"microsoft",3=>"samsung",22=>"hp");

//and

$query = 'SELECT * FROM categ;
$result = mysql_query ($query) or die ('Query Faild: '. mysql_error());

   while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
      $count++; 
    $categ[] = $line;
     $item = explode(":", $line['item']);
}



in tpl i need to convert explode code and make some moves

becouse in db i have 10:22 ori 10:3

if i try in tpl
-------------------------

Code:
{$line.item|explode:":":""}


i receive in html

Code:
array


if i try in tpl
-----------------------
//becouse in db i have 10:3

Code:
{$categ[$line.item|explode:":":""]} // to create array {$categ[10]} that represent apple and {$categ[3]} that represent samsung


i receive error

Code:
Warning: explode() [function.explode]: Empty delimiter in ...line 22


where do you think that i am wrong?
_________________
be fiRst but fiRst think fiRst!


Last edited by mozolici on Tue May 26, 2009 6:14 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
mohrt
Administrator


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

PostPosted: Tue May 26, 2009 6:13 pm    Post subject: Reply with quote

explode in PHP, then assign to the template?
Back to top
View user's profile Send private message Visit poster's website
mozolici
Smarty Rookie


Joined: 18 Aug 2007
Posts: 21
Location: Suceava / Romania

PostPosted: Tue May 26, 2009 7:40 pm    Post subject: Reply with quote

i create 2 arrays in php with explode

this code in tpl works
----------------
Code:
//first array
{$arrayFirst[$line.id][0]}       --- output // 10 
{$arrayFirst[$line.id][1]}       --- output // 3

//second array
{$arraySecond[10]}            --- output // apple
{$arraySecond[3]}            --- output // samsung



i want to make a combination with 2 arrays to create a dynamic site and i want to modify second array

this code
------------------
Code:
{$arraySecond[10]}   // instead 10 to put {$arrayFirst[$line.id][0]}



something like this ... but dosent work

Code:
{$arraySecond[$arrayFirst[$line.id][0]}]}//to make dinamically


any solution
_________________
be fiRst but fiRst think fiRst!
Back to top
View user's profile Send private message Visit poster's website
mozolici
Smarty Rookie


Joined: 18 Aug 2007
Posts: 21
Location: Suceava / Romania

PostPosted: Tue May 26, 2009 8:41 pm    Post subject: Reply with quote

i used assign var="foo"

and works

topic closed
_________________
be fiRst but fiRst think fiRst!
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 -> General 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