Blogroll

photoshop cs6 html 5 css php seo backlinks

adsense

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}

0 comments:

Post a Comment