Created
November 12, 2015 10:40
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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