| ||||||||||
![]() |
Shopping cart software Solutions for online shops and malls | |||||||||
![]() |
![]() |
|
X-Cart Home | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
New template | |||
![]() |
|
|
Thread Tools | Search this Thread |
#1
|
|||||||
|
|||||||
![]() I finally figured out how to pass variables from php to smarty, however I'm stuck on one thing.
Here's what I did: 1. Created a simple php file that runs through a MySQL query and brings back a series of items from a news table - the db and table I'm accesing is totally independent from x-cart. 2. created a new smarty template that displays a simple table within my customer/home.tpl file. What I want to do: display the sql query file in the new smarty template I created. What do I need to do to the php file? What do I need to do to the smarty template file? What do I need to do to the home.php and home.tpl files? I have managed to pass all the variables I use on the sql query to the smarty template, I defined those in home.php ($smarty->asign...), I just can't get the smarty template to display the results of the query. Thanks in advance. |
|||||||
#2
|
|||||||
|
|||||||
![]() if for instance your php file had a query in it like:
$results=func_query(blah blah); $smarty->assign("myquery",$results); You need to access the elements of the results array similar to the way it is done with products or categories ie include the file: { include file="mytemplate.tpl" } then put in a section: {section name=myquery loop=$myquery} then within this section (dont forget to close it at the end) put in something like: {$myquery.fieldname} or something fairly similar. ![]()
__________________
ex x-cart guru ![]() |
|||||||
#3
|
|||||||
|
|||||||
![]() OK, I'll give it a shot,
Thanks for the info... |
|||||||
#4
|
|||||||
|
|||||||
![]() OK,
I've moved much further along. The query is being executed and bringing back the resutls I want (I echoed them from the query and they showed up on my page), However, they are not displaying in the template file I have created. Right now I have this is my template file: {section name=news loop=$newsItems} Title: {$newsItems.title} {/section} this is my php file: <? $dbCon=mysql_connect("host","user","pass") or die("Could not connect to the database"); mysql_select_db($dBName,$dbCon); $SQLCon="SELECT title,ID,description,category,date FROM articles WHERE visible = 1 AND date<=NOW() AND category<>10 ORDER BY date DESC, ID DESC LIMIT 7 "; $newsItems=mysql_query($SQLCon); //while ($rs=mysql_fetch_array($newsItems)) // { // echo "$rs[title] | $rs[date] \n"; // echo "$rs[description]\n"; // echo " \n"; // } $smarty->assign("newsItems",$newsItems); ?> Thanks again... |
|||||||
#5
|
|||||||
|
|||||||
![]() sorry had a small typo in my message - i have now corrected it. doh!
$smarty->assign("myquery",$results);
__________________
ex x-cart guru ![]() |
|||||||
#6
|
|||||||
|
|||||||
![]() Quote:
Figured it out ![]() Still, see my message above, I'm getting closer and closer to it... |
|||||||
#7
|
|||||||
|
|||||||
![]() ![]() no matter what I do i can't ge the results to show up on my template... I've tried mimicking the producs query, but still no progress.. Please help. |
|||||||
#8
|
|||||||
|
|||||||
![]() Okay,
your php script should be: Code:
This shoudl be included in customer/home.php Then in your template: Code:
Code:
__________________
ex x-cart guru ![]() |
|||||||
#9
|
|||||||
|
|||||||
![]() ![]() That worked like a charm and did exactly what I needed. I REALLY REALLY APPRECIATE your help, with it, I've learned lots along the way... I'll post a URL when the site is finished. Thanks again! |
|||||||
|
|||
X-Cart forums © 2001-2020
|