View Single Post
  #12  
Old 04-12-2017, 05:17 PM
 
simetria simetria is offline
 

Advanced Member
  
Join Date: Jul 2013
Posts: 77
 

Default Re: Proper way for query functionality

Hi guys, sorry for re-hashing this post.

As I previously mentioned I have everything wired up from product.php to product.tpl with a simple string being passed along. Now reverting to my original question about sending over a query to the tpl file.

If I am running a SELECT * query and assign it to the smarty var I can see the array or rows and the array of columns being passed along with a print_r. The trouble I am running into is, where do i run the foreach loop - in the php file or the tpl file? In addition, where do you stipulate the column's name of the data being retrieved in this type of setup - in this case image_path column?

Here's what I have so far:

PHP
PHP Code:
$q " SELECT * FROM some_table ";
$r func_query($q);
$smarty->assign('data'$r); 

TPL
PHP Code:
{foreach from=$data name=row item=t}
  {foreach 
from=$t item=z}
    <
img href="{$z}/>
  {/foreach}
{/foreach} 

At the moment, what I am getting is an img tag for every column in every row - and I understand why. But when I try to specify a certain column name, no matter where I do it, I can't get it to out put only that column for each of the rows. I've tried using column name as such ['image_path'] and also the index as such [0].

ALSO - For some strange reason, even the img path columns do not display the image properly. it shows the path saved in the db inside the href, but does not display the image on the page - strange. I can see the path is correct because with dev tools if I right click over the href and choose open in new tab, it opens the image with no issues.

Any input guys is really appreciated.

Thank you again.

-S
__________________
Thanks.
Reply With Quote