geormanth Posted September 21, 2010 Share Posted September 21, 2010 I am trying to have the products in to homepage. I notice after {debug} that the products.tpl has some variables that homepage doesnt. I make the following php to have the variables but with no results. <?php include("dbconnect.php"); include("includes/functions.php"); $query = "SELECT * FROM `tblproducts` WHERE 1 LIMIT 0, 30 "; $result = mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; echo("<p><font color=#cccccc>$id</font> - <b>$type</b><br>$description</p>"); } ?> the php works fine but dont pass variables to tpl so I can call them in homepage. Please Help George 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted September 21, 2010 Share Posted September 21, 2010 (edited) I am trying to have the products in to homepage. I notice after {debug} that the products.tpl has some variables that homepage doesnt. I make the following php to have the variables but with no results. <?php include("dbconnect.php"); include("includes/functions.php"); $query = "SELECT * FROM `tblproducts` WHERE 1 LIMIT 0, 30 "; $result = mysql_query($query); while ($data = mysql_fetch_array($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; echo("<p><font color=#cccccc>$id</font> - <b>$type</b><br>$description</p>"); } ?> the php works fine but dont pass variables to tpl so I can call them in homepage. Please Help George Try this I also have added some other one's you may need: include("dbconnect.php"); include("includes/functions.php"); $result = select_query ('tblproducts', '', array ('hidden' => ''), 'order', 'DESC', '0,30'); while ($data = mysql_fetch_array ($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; $products[] = array ('id' => $id, 'type' => $type, 'gid' => $gid, 'name' => $name, 'description' => $description); } $smartyvalues['products'] = $products; $result1 = select_query ('tblannouncements', '', array ('published' => 'on'), 'date', 'DESC', '0,3'); while ($data1 = mysql_fetch_array ($result1)) { $id = $data1['id']; $date = $data1['date']; $title = $data1['title']; $announcement = $data1['announcement']; $date = frommysqldate ($date); $announcements[] = array ('id' => $id, 'date' => $date, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($announcement)); } $smartyvalues['announcements'] = $announcements; $result2 = select_query ('tblknowledgebase', '', array ('private' => ''), 'views', 'DESC', '0,3'); while ($data2 = mysql_fetch_array ($result2)) { $id = $data2['id']; $title = $data2['title']; $article = $data2['article']; $views = $data2['views']; $knowledgebase[] = array ('id' => $id, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($article), 'views' => $views); } $smartyvalues['knowledgebase'] = $knowledgebase; then in your tpl file put this: {foreach from=$products item=product} <p><font color=#cccccc>{$product.id}</font> - <b>{$product.type}</b><br>{$product.description}</p> {/foreach} p.s order = sort order Edited September 21, 2010 by thehost5968 0 Quote Link to comment Share on other sites More sharing options...
geormanth Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks your your quick response. I will check it and let you know. One last question the php file where is better to insert 1. in header 2. inside the custom page from whmcs 3. independent and make an include {php}..{/php} inside tpl 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted September 21, 2010 Share Posted September 21, 2010 #2 in a custom page in a php file then the foreach in the tpl of the custom page. as per: http://wiki.whmcs.com/Creating_Pages 0 Quote Link to comment Share on other sites More sharing options...
geormanth Posted September 21, 2010 Author Share Posted September 21, 2010 I test it and nothing happen I dont see the variables in {debug} again here is my php please let me know where I make mistake? Thanks again for your time <?php define("CLIENTAREA",true); require("dbconnect.php"); require("includes/functions.php"); require("includes/clientareafunctions.php"); $pagetitle = $_LANG['webhostpackages']; $pageicon = "images/support/clientarea.gif"; $breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>'; $breadcrumbnav .= ' > <a href="mypage.php">My Page</a>'; initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav); if ($_SESSION['uid']) { # User is Logged In - put any code you like here } # To assign variables in Smarty use the following syntax. # This can then be used as {$variablename} in the template $smartyvalues["variablename"] = $value; # Define the template filename to be used without the .tpl extension $templatefile = "test"; outputClientArea($templatefile); include("dbconnect.php"); include("includes/functions.php"); $result = select_query ('tblproducts', '', array ('hidden' => ''), 'order', 'DESC', '0,30'); while ($data = mysql_fetch_array ($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; $products[] = array ('id' => $id, 'type' => $type, 'gid' => $gid, 'name' => $name, 'description' => $description); } $smartyvalues['products'] = $products; $result1 = select_query ('tblannouncements', '', array ('published' => 'on'), 'date', 'DESC', '0,3'); while ($data1 = mysql_fetch_array ($result1)) { $id = $data1['id']; $date = $data1['date']; $title = $data1['title']; $announcement = $data1['announcement']; $date = frommysqldate ($date); $announcements[] = array ('id' => $id, 'date' => $date, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($announcement)); } $smartyvalues['announcements'] = $announcements; $result2 = select_query ('tblknowledgebase', '', array ('private' => ''), 'views', 'DESC', '0,3'); while ($data2 = mysql_fetch_array ($result2)) { $id = $data2['id']; $title = $data2['title']; $article = $data2['article']; $views = $data2['views']; $knowledgebase[] = array ('id' => $id, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($article), 'views' => $views); } $smartyvalues['knowledgebase'] = $knowledgebase; ?> 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted September 21, 2010 Share Posted September 21, 2010 put this in a php file named test.php <?php define("CLIENTAREA",true); require("dbconnect.php"); require("includes/functions.php"); require("includes/clientareafunctions.php"); $pagetitle = $_LANG['webhostpackages']; $pageicon = "images/support/clientarea.gif"; $breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>'; $breadcrumbnav .= ' > <a href="test.php">Teste</a>'; initialiseClientArea($pagetitle,$pageicon,$breadcr umbnav); if ($_SESSION['uid']) { # User is Logged In - put any code you like here } # To assign variables in Smarty use the following syntax. # This can then be used as {$variablename} in the template $result = select_query ('tblproducts', '', array ('hidden' => ''), 'order', 'DESC', '0,30'); while ($data = mysql_fetch_array ($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; $products[] = array ('id' => $id, 'type' => $type, 'gid' => $gid, 'name' => $name, 'description' => $description); } $smartyvalues['products'] = $products; $result1 = select_query ('tblannouncements', '', array ('published' => 'on'), 'date', 'DESC', '0,3'); while ($data1 = mysql_fetch_array ($result1)) { $id = $data1['id']; $date = $data1['date']; $title = $data1['title']; $announcement = $data1['announcement']; $date = frommysqldate ($date); $announcements[] = array ('id' => $id, 'date' => $date, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($announcement)); } $smartyvalues['announcements'] = $announcements; $result2 = select_query ('tblknowledgebase', '', array ('private' => ''), 'views', 'DESC', '0,3'); while ($data2 = mysql_fetch_array ($result2)) { $id = $data2['id']; $title = $data2['title']; $article = $data2['article']; $views = $data2['views']; $knowledgebase[] = array ('id' => $id, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($article), 'views' => $views); } $smartyvalues['knowledgebase'] = $knowledgebase; # Define the template filename to be used without the .tpl extension $templatefile = "test"; outputClientArea($templatefile); ?> then put this in a file named test.tpl within your template folder: {foreach from=$products item=product} <p><font color=#cccccc>{$product.id}</font> - <b>{$product.type}</b><br>{$product.description}</p> {/foreach} 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted September 21, 2010 Share Posted September 21, 2010 OK just tested this and you need to replace the php file content with this (this one works): <?php define("CLIENTAREA",true); require("dbconnect.php"); require("includes/functions.php"); require("includes/clientareafunctions.php"); $pagetitle = $_LANG['clientareatitle']; $pageicon = "images/support/clientarea.gif"; $breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>'; $breadcrumbnav .= ' > <a href="mypage.php">My Page</a>'; initialiseClientArea($pagetitle,$pageicon,$breadcrumbnav); if ($_SESSION['uid']) { # User is Logged In - put any code you like here } # To assign variables in Smarty use the following syntax. # This can then be used as {$variablename} in the template $result = select_query ('tblproducts', '', array ('hidden' => ''), 'order', 'DESC', '0,30'); while ($data = mysql_fetch_array ($result)) { $id = $data["id"]; $type = $data["type"]; $gid = $data["gid"]; $name = $data["name"]; $description= $data["description"]; $products[] = array ('id' => $id, 'type' => $type, 'gid' => $gid, 'name' => $name, 'description' => $description); } $smartyvalues['products'] = $products; $result1 = select_query ('tblannouncements', '', array ('published' => 'on'), 'date', 'DESC', '0,3'); while ($data1 = mysql_fetch_array ($result1)) { $id = $data1['id']; $date = $data1['date']; $title = $data1['title']; $announcement = $data1['announcement']; $date = frommysqldate ($date); $announcements[] = array ('id' => $id, 'date' => $date, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($announcement)); } $smartyvalues['announcements'] = $announcements; $result2 = select_query ('tblknowledgebase', '', array ('private' => ''), 'views', 'DESC', '0,3'); while ($data2 = mysql_fetch_array ($result2)) { $id = $data2['id']; $title = $data2['title']; $article = $data2['article']; $views = $data2['views']; $knowledgebase[] = array ('id' => $id, 'title' => $title, 'urlfriendlytitle' => getmodrewritefriendlystring ($title), 'text' => strip_tags ($article), 'views' => $views); } $smartyvalues['knowledgebase'] = $knowledgebase; # Define the template filename to be used without the .tpl extension $templatefile = "test"; outputClientArea($templatefile); ?> 0 Quote Link to comment Share on other sites More sharing options...
geormanth Posted September 21, 2010 Author Share Posted September 21, 2010 Thanks a lot And the other works if you fix $breadcr umbnav to $breadcrumbnav did you make any other change to the last one? the products prints from 3 to 1 if I want to prints from 1 to 3 how I change the order (ofcourse I can doit from db directly change the numbers) But do you have a better solution in mind 0 Quote Link to comment Share on other sites More sharing options...
thehost5968 Posted September 21, 2010 Share Posted September 21, 2010 (edited) No there was no other changes just the breadcr umbnav. that would be within the php coding: DESC to ASC ofcourse I can doit from db directly change the numbers : No if you ever need to change this numbering you just set / change the product sort order within the product details page in admin? (I all ways use sort order over the ID as a product may have a ID of say product 1 = id#1 sortorder#1, product 2 = id#110 sortorder#2 and product 3 = id#5 sortorder#3.) so sort order should all ways get set. Edited September 21, 2010 by thehost5968 0 Quote Link to comment Share on other sites More sharing options...
geormanth Posted October 5, 2010 Author Share Posted October 5, 2010 and if you want to have the price for each product 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.