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

problem in smarty 2.5 ?

 
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
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 11:24 am    Post subject: problem in smarty 2.5 ? Reply with quote

hi there, its me again :=)

and i got a problem again, i used old smarty version 24x before, then i upgraded to 2.5 and now something dont work .

i used to get my db select into an array like this.

Code:

$query="SELECT * FROM .........;
   
$products_query = $db->Execute($query);
while ($products = $products_query->fields) {

$product_listing_data[$nr]=array(
      'PRODUCT_NAME'=>$products['products_name']);


 $products_query->MoveNext();
}

$smarty->assign('product_listing',$product_listing_data);
$product_listing=$smarty->fetch(CURRENT_TEMPLATE.'product_listing_cat.html');
return($product_listing);


and im my template file i use this.


Code:

{foreach name=aussen item=product_listing from=$product_listing}

{$product_listing.PRODUCT_NAME}

{/foreach}


but nothing getting displayed ;/ , there is only 1 dataset in db right now, so if i use:

Code:

$query="SELECT * FROM .........;
   
$products_query = $db->Execute($query);
while ($products = $products_query->fields) {

$smarty->assign('PRODUCT_NAME',$products['products_name']);


 $products_query->MoveNext();
}


$product_listing=$smarty->fetch(CURRENT_TEMPLATE.'product_listing_cat.html');
return($product_listing);


Code:

{$PRODUCT_NAME}



it works.

any suggestions for another solution getting my data into an array?
thanky,
mario
Back to top
View user's profile Send private message Visit poster's website
aloner
Smarty Rookie


Joined: 24 Apr 2003
Posts: 24

PostPosted: Sun May 11, 2003 11:51 am    Post subject: Reply with quote

print_r($product_listing_data)
_________________
Your ad here.
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 12:21 pm    Post subject: ? Reply with quote

Quote:

print_r($product_listing_data)


?

i just wanna get my data into an array, and display each single array element between a {foreach}{/foreach}

but dont work anymore since i upgraded ;/
Back to top
View user's profile Send private message Visit poster's website
Wom.bat
Smarty Pro


Joined: 24 Apr 2003
Posts: 107
Location: Munich, Germany

PostPosted: Sun May 11, 2003 12:56 pm    Post subject: Reply with quote

of course it doesn't, if you have the same name for the foreach-inner array and the outer one.
change

{foreach name=aussen item=product_listing from=$product_listing}

to

{foreach name="aussen" item="product_entry" from=$product_listing}

and use $product_entry in the loop
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 1:52 pm    Post subject: Reply with quote

well if i wanna try that:

$test_array=array();
$test_array['PRODUCT_NAME']='';
$test_array['PRODUCT_NAME'] .='Wert1';
$test_array['PRODUCT_NAME'] .='Wert2';

$smarty->assign('product_listing_data',$test_array);
$product_listing=$smarty->fetch(CURRENT_TEMPLATE.'product_listing_cat.html');


and in my template

{foreach name=aussen item=product from=$product_listing_data}
{$product.PRODUCT_NAME}
{/foreach}

then i get this output on my Page:

W

nothing else ;/
also same if i use
{foreach name="aussen" item="product" from=$product_listing_data}
Back to top
View user's profile Send private message Visit poster's website
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Sun May 11, 2003 2:10 pm    Post subject: Reply with quote

in your example $product is a string and not an array, so {$product.PRODUCT_NAME} produces crap.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 2:20 pm    Post subject: Reply with quote

but the code i postet in 1st post, did worked until i upgraded ?

so how else i can get data in this array ?

$product_listing_data[$nr]=array(
      'PRODUCT_NAME'=>$products['products_name'],
'PRODUCT_IMAGE'=>$products['products_image']
);

and display it in my template ?

*edit* ok i lokadet the problem ~ ill try to fix, got a problem with my db select ;/
_________________
[quote]
http://www.xt-commerce.com
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: Sun May 11, 2003 2:37 pm    Post subject: Reply with quote

mzanier_XTC -- hello again!

Quote:
but the code i postet in 1st post, did worked until i upgraded ?


Then I don't think you are showing all of the relevant code Wink

In your example above, you are only showing two pieces of template code and neither looks broken. Either you changed your PHP code or you have more template code you aren't telling us about.

For example, in your PHP this looks problematic:
Code:
$product_listing_data[$nr]=array(
      'PRODUCT_NAME'=>$products['products_name']);

What is $nr? You then use:

Code:
$smarty->assign('product_listing',$product_listing_data);


Wom.Bat's comments follow from there because you try to use $product_listing.PRODUCT_NAME which is obviously not the way your data is setup.

You may have other template code that you are not showing Smile. Be aware of changes in 2.5.0 -- read the NEWS file in the distribution package. If you are using dot-notation for arrays be aware of changes regarding back-ticks [see: http://smarty.php.net/manual/en/language.syntax.quotes.php].

HTH.
Back to top
View user's profile Send private message
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 2:40 pm    Post subject: Reply with quote

i got it. Idea i'm an idiot Very Happy

forgot
$row++;
$nr++;
hehe Cool
_________________
[quote]
http://www.xt-commerce.com
Back to top
View user's profile Send private message Visit poster's website
mzanier_XTC
Smarty Regular


Joined: 04 May 2003
Posts: 38

PostPosted: Sun May 11, 2003 4:37 pm    Post subject: Re: problem in smarty 2.5 ? Reply with quote

ok, now its working, here is the code if some1 else want to do the same Wink

Code:

$query="SELECT * FROM .........;
   
$products_query = $db->Execute($query);
while ($products = $products_query->fields) {

$row++;
$nr++;

$product_listing_data[$nr]=array(
      'PRODUCT_NAME'=>$products['products_name'],
                  'PRODUCT_IMAGE'=>$products['products_image']);

 $products_query->MoveNext();
}

$smarty->assign('product_listing_data',$product_listing_data);
$product_listing=$smarty->fetch(CURRENT_TEMPLATE.'product_listing_cat.html');
return($product_listing);


and im my template file i use this.


Code:

{foreach name=aussen item=product_data from=$product_listing_data} 

{$product_data.PRODUCT_NAME}
{$product_data.PRODUCT_IMAGE}

{/foreach}



* thanks Wink *
_________________
[quote]
http://www.xt-commerce.com
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