Im n00b, so basically i want to call my query which is located in my index.php file from my .tpl file using smarty:
Index.php
<?php
//Database connection
$db = mysqli_connect('xx','xx','','xx')
or die('Error connecting to MySQL server.');
//access Smarty template engine
require_once('Smarty-3.1.30/libs/Smarty.class.php');
$smarty = new Smarty();
$smarty->template_dir = 'views';
$smarty->compile_dir = 'tmp';
//query product page
$query = "SELECT * FROM cs_shop";
mysqli_query($db, $query) or die('Error querying database.');
$result = mysqli_query($db, $query);
$row = mysqli_fetch_array($result);
//query
while ($row = mysqli_fetch_array($result)) {
$row['product_category'] . ' ' . $row['product_price'] . ': ' .
$row['product_quantity'] . ' ' . $row['product_about'] .' '
.$row['product_color'] .'<br />';
}
//db collect data
$smarty->assign('row', $row);
//template
$smarty->display('index.tpl');
mysqli_close($db);
?>
The while loop i use in the index.php is what i want to call in my .tpl file, im new to smarty and cant get it to work , test database connection and it worked, my , Smarty gets called no errors.
Its a basic static page im just doing experiment, using Smarty, So i just want to display the query as list no td's or anything like that.
So can someone give me a example how my .tpl file would look located in my 'views' directory if i want to display the query?
Thanks in advance
{foreach from=$row item="item"} {$item} {/foreach}. This will output everything in$row, which is an array. Also your code doesn't work now, there are errors, e.g. inside the while you contenate strings but don't assign them to a variable.