Forum : converting code into smarty
Brief description  about Online courses   join in Online courses
View Gopinath Raghurama Damale 's Profile

converting code into smarty

Dear Sir, please help me do this assignment.

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 "nDatabase error: ".mysql_error()."
n";
die("MySQL Said: " . mysql_error());
}

$user = array();

?>




while($tmp = mysql_fetch_assoc($result))

{
?>



}
?>
Asked by Gopinath Raghurama Damale | Sep 11, 2010 |  Reply now
Replies (2)
View gopinath raghurama damale 's Profile
thank you sir, I will try to do the assignment.
Sep 15, 2010
View teacher siliconindia 's Profile
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



Sep 15, 2010