Forum : Covert the following piece of code into smarty template.
Brief description  about Online courses   join in Online courses
View Raghavendra  CN 's Profile

Covert the following piece of code into smarty template.

Dear Sir, I can not understand the following questions.. For the 1st question, can i just assign the text "This is my first smarty example" to a variable say "name" and just insert {$name} in the template file?

For the 2nd question, can i create database? i am really get confuse how to solve these question.. Please help me and i want to submit this assignment within in 4 days...So pls pls help me....
1) Covert the following piece of code into smarty template.





echo "This is my first smarty example";
?>




2) Piece of code below contains database queries, PHP and HTM all in one. Convert the following piece of code into smarty.


//db configuration
include "config.php";

if(!($db = @mysql_connect($server, $db_user, $db_pass))) //connect to database
die("Couldn't connect to the database.");
if(!@mysql_select_db($db_name, $db)) //select database
die("Database doesn't exist!");

$sql = "SELECT * FROM users";

if(($result = @mysql_query($sql, $db)) == 0)
{
echo "n
Database error: ".mysql_error()."
n";
die("MySQL Said: " . mysql_error());
}

$user = array();

?>




while($tmp = mysql_fetch_assoc($result))

{
?>



}
?>
Asked by Raghavendra CN | Sep 18, 2010 |  Reply now
Replies (2)
View raghavendra cn 's Profile
Thank you....
Sep 20, 2010
View teacher siliconindia 's Profile
Hi raghavendra,

First of all we need to separate HTML code as tpl and what ever php code is we will write in php file for example example.php, here we will assign the values what ever we need to display in template page as follows,
$smarty->assign("anyname",$name); (if multiple assignments required just do the same).
In smarty template we will display the value by using {$anyname} which ever name we assigned in example.php

Thanks
Sep 19, 2010