Jump to content

More Variables


geormanth

Recommended Posts

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

Link to comment
Share on other sites

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 by thehost5968
Link to comment
Share on other sites

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;

 

?>

Link to comment
Share on other sites

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} 			 		

Link to comment
Share on other sites

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);
?> 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by thehost5968
Link to comment
Share on other sites

  • 2 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated