HOME BLOG PORTFOLIO PHOTO CONTACT Admin Login
php sending data in json format

php sending data in json format very useful for flex or js or javascript from php integration, and when flex guys no idea about php or php guy no idea about flex then format like this way(below):

PHP CODE ADDING DATA

<?php
include(“include/db.php”);
#Add_Roles Start
if($_POST['method']==”Add_Roles”)
{
/*$msg=’{“data”:{“Error”:”1″,”message”:”Under Construction”}}’;
echo $msg;
return; */
if($_POST['name']==”")
{
$msg=’{“data”:{“Error”:”1″,”message”:”name Required”}}’;
echo $msg;
return;
}
$qry=”SELECT * FROM roles WHERE name=’”.$_POST['name'].”‘ “;
$result = mysql_query ($qry) or die(“Error1 class.Roles.php”.mysql_error());
$num=mysql_num_rows($result);
if($num)
{
$msg=’{“data”:[{"Error":"1","message":"this Record allready Registred"}]}’;
echo $msg;
return;
}
$qry=”INSERT INTO roles SET name=’”.$_POST['name'].”‘”;
$result=mysql_query($qry) or die(“Error2 class.Roles.php”.mysql_error());
if($result)
{
$msg=’{“data”:{“Success”:”1″,”message”:”Registred successfully”}}’;
echo $msg;
return;
}
else
{
$msg=’{“data”:{“Error”:”1″,”message”:”Registred Error”}}’;
echo $msg;
return;
}
}
#Add_Roles End
{/code}

PHP CODE GETTING DATA without or with (for both) array format
{code type=codetype}
#Get_Roles Start
if($_POST['method']==”Get_Roles”)
{
$qry=”SELECT * FROM roles”;
$result=mysql_query($qry) or die(“Error3 class.Roles.php”.mysql_error());
$num=mysql_num_rows($result);
if($num)
{
while($row=mysql_fetch_array($result))
{
$echodata1.=’{‘.’”id”:”‘.$row['id'].’”,”name”:”‘.$row['name'].’”},’;
}
$echodata1=substr($echodata1,0,-1);
$echodata = ‘{“data”:['.$echodata1.']}’;
echo $echodata;
return;
}
}
#Get_Roles end

?>

 

   Share on Facebook

Page views:743