Skip to content

Instantly share code, notes, and snippets.

@walteranyika
Created November 12, 2015 10:40
Show Gist options
  • Save walteranyika/341736ec492a8573fc46 to your computer and use it in GitHub Desktop.
Save walteranyika/341736ec492a8573fc46 to your computer and use it in GitHub Desktop.
Sample code for JSON Data. It fetches and encodes data into JSON format
<?php
header("content-type:application/json");
mysql_connect("localhost","root","");
mysql_select_db("database");
$sql="select * from table";
$data=array();
$results=mysql_query($sql);
while($r=mysql_fetch_row($results))
{
$data[] = array("title"=>$r[1],"author"=>$r[2]);
}
echo json_encode($data);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment