Blogroll

photoshop cs6 html 5 css php seo backlinks

adsense

Smarty Template Engine Step by Step Tutorial

Smarty has focused on how to help you make an high-performance, scalability, security and future growth application.

JavaScript was designed to add interactivity to HTML pages

JavaScript’s official name is ECMAScript, which is developed and maintained by the ECMA International organization.

This is default featured slide 3 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 4 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

This is default featured slide 5 title

Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.

Showing posts with label smarty. Show all posts
Showing posts with label smarty. Show all posts

Monday, 24 February 2014

How to Insert and Select data from Database using Loop?

First we create form in tpl file
<form action="../demo/smart.php" method="post">
Name<input name="name"></input>
Pass<input name="pass"></input>
repass<input name="repass"></input>
email<input name="email"></input>
age<input name="age"></input>
<input type="submit"></input>
</form>

Then we will collect the values of input in php page
<?php
if(isset($_REQUEST["name"]))
{
$name=$_REQUEST["name"];
$pass=$_REQUEST["pass"];
$repass=$_REQUEST["repass"];
$email=$_REQUEST["email"];
$age=$_REQUEST["age"];
}
//then 
    $sql="insert into smart(name, pass, repass, email, age)values('".$name."', '".$pass."', '".$repass."', '".$email."', '".$age."')";
    mysql_query($sql);
?>
now your insert form is finished. Now you are selecting this record using loop
in php
$get="select * from smart";
$git=mysql_query($get);
$smarty = new Smarty;

$yes=array();
while($s=mysql_fetch_array($git))
{
                              $yes[]=array('idw'=>$s["id"],
                                'nam'=>$s["name"],
                                'pas'=>$s["pass"],
                                'repas'=>$s["repass"],
                                'ema'=>$s["email"],
                                'ag'=>$s["age"]);
}
$smarty->assign("results",$yes);

$smarty->display('smart.tpl');
?>
Now in tpl

<ul> 
{foreach from=$results item=abc}
{foreach from=$abc key=k item=v}
<li>{$k}: {$v}</li>
{/foreach}  
{/foreach}

How to access value from http parameter and others? Reversed Variable

Smarty Variable Step by Step Tutorial - Part 5: Following how to access value from http parameter and others:
GET
From this url: http://localhost/test/smarty/test.php?page=about
1<html>
2  <head>
3    <title>Page {$smart.get.page}</title>
4  </head>
5  <body bgcolor="{#bodyColor#}">
6    page: {$smarty.get.page} <br>
7  </body>
8</html>
POST
Example from http Post:
1{$smarty.post.page}
Cookie
Example from cookie "page":
1{$smarty.cookie.page}
SERVER
1{$smarty.server.SERVER_NAME}
session
Example from session "page":

1{$smarty.session.page}

Variable at Configuration File: Smarty Variable

Smarty Variable Step by Step Tutorial - Part 4: We can store variables at configuration file. For this job, we must create a folder named configs within root application (example, www/test/smarty). So, we have www/test/smarty/configs.
Create a configuration file with conf extension, such as "setting.conf". Enter following sample code:
1pageTitle = "Hello, World"
2bodyColor = "#EAEAEA"
Next, build template by create a file named "test.tpl" within template. Enter following code
01{config_load file="setting.conf"}
02<html>
03  <head>
04    <title>{#pageTitle#}</title>
05  </head>
06  <body bgcolor="{#bodyColor#}">
07    id : {$contact->id} <br>
08    name : {$contact->name} <br>   
09    email : {$contact->email} <br>   
10    phone : {$contact->phone} <br>   
11  </body>
12</html>
Create a file named "test.php" enter following code:

01<?php
02require 'Smarty/libs/Smarty.class.php';
03 
04class Contacts{
05  var $id   = 1;
06  var $name = 'wiwit';
07  var $email = 'wsiswoutomo at yahoo dot com';
08  var $phone = '123456789';
09}
10 
11$contact = new Contacts;
12 
13$smarty = new Smarty;
14 
15$smarty->assign('contact',$contact);
16$smarty->display('test.tpl');
17?>