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

display product_id in foreach?

 
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
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Mon Apr 01, 2013 1:17 pm    Post subject: display product_id in foreach? Reply with quote

sorry my bad english..

i write e-commerce script. but

Code:
{foreach item=cart from=$shopcart}
   <tr>
      <td>{$cart->product_ID}</td>
   </tr>
{/foreach}


this my shopping cart template. $shopcart is in database shopcart table.

but i use $cart->product_ID and product name id products table ?
Back to top
View user's profile Send private message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Mon Apr 01, 2013 2:32 pm    Post subject: Reply with quote

pls help me Sad
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Mon Apr 01, 2013 6:21 pm    Post subject: Reply with quote

this isn't part of smarty, sounds like shopping cart software, check their forums?
Back to top
View user's profile Send private message Visit poster's website
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Tue Apr 02, 2013 6:50 am    Post subject: Reply with quote

mohrt wrote:
this isn't part of smarty, sounds like shopping cart software, check their forums?


no no this is my script. Im write new script.

and product_ID in cart sql table. product info is product table.

i want use {$cart->product_ID} and product->name in product table??

Code:
{foreach item=cart from=$shopcart}
   <tr>
      <td>HIDDEN {$cart->product_ID} /HIDDEN {$product->name}</td>
   </tr>
{/foreach}
Back to top
View user's profile Send private message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Tue Apr 02, 2013 6:57 am    Post subject: Reply with quote

Code:
$carts = $db->get_results("SELECT * FROM carts");
foreach ($carts AS $cart){
$product = $db->get_row("SELECT * FROM products WHERE id='$cart->product_ID'");
echo $product->name;
}


i want this in smarty!
Back to top
View user's profile Send private message
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Apr 04, 2013 6:37 am    Post subject: Reply with quote

Sad help me pls..
Back to top
View user's profile Send private message
mohrt
Administrator


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

PostPosted: Thu Apr 04, 2013 1:59 pm    Post subject: Reply with quote

Code:
$carts = $db->get_results("SELECT * FROM carts");
foreach ($carts AS $idx=>$cart){
  $carts[$idx]->product = $db->get_row("SELECT * FROM products WHERE id='{$cart->product_ID}'");
}
$smarty->assign('carts',$carts);


Code:
{foreach item=cart from=$carts}
  {$cart->product_ID}
  {$cart->product->name}
{/foreach}
Back to top
View user's profile Send private message Visit poster's website
ulast
Smarty Rookie


Joined: 01 Apr 2013
Posts: 11

PostPosted: Thu Apr 04, 2013 4:52 pm    Post subject: Reply with quote

yesss!! thank you my friend! Smile
Back to top
View user's profile Send private message
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