View previous topic :: View next topic |
Author |
Message |
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 11:24 am Post subject: problem in smarty 2.5 ? |
|
|
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);
|
it works.
any suggestions for another solution getting my data into an array?
thanky,
mario |
|
Back to top |
|
aloner Smarty Rookie
Joined: 24 Apr 2003 Posts: 24
|
Posted: Sun May 11, 2003 11:51 am Post subject: |
|
|
print_r($product_listing_data) _________________ Your ad here. |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 12:21 pm Post subject: ? |
|
|
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 |
|
Wom.bat Smarty Pro
Joined: 24 Apr 2003 Posts: 107 Location: Munich, Germany
|
Posted: Sun May 11, 2003 12:56 pm Post subject: |
|
|
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 |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 1:52 pm Post subject: |
|
|
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 |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Sun May 11, 2003 2:10 pm Post subject: |
|
|
in your example $product is a string and not an array, so {$product.PRODUCT_NAME} produces crap. |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 2:20 pm Post subject: |
|
|
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 |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun May 11, 2003 2:37 pm Post subject: |
|
|
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
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 . 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 |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 2:40 pm Post subject: |
|
|
i got it. i'm an idiot
forgot
$row++;
$nr++;
hehe _________________ [quote]
http://www.xt-commerce.com |
|
Back to top |
|
mzanier_XTC Smarty Regular
Joined: 04 May 2003 Posts: 38
|
Posted: Sun May 11, 2003 4:37 pm Post subject: Re: problem in smarty 2.5 ? |
|
|
ok, now its working, here is the code if some1 else want to do the same
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 * _________________ [quote]
http://www.xt-commerce.com |
|
Back to top |
|
|