Table Structure:
-- phpMyAdmin SQL Dump
-- version 4.1.14
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Jan 06, 2016 at 10:32 AM
-- Server version: 5.6.17
-- PHP Version: 5.5.12
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `users1`
--
-- --------------------------------------------------------
--
-- Table structure for table `users1`
--
CREATE TABLE IF NOT EXISTS `users1` (
`u_ref` bigint(20) NOT NULL AUTO_INCREMENT,
`u_firstname` varchar(255) NOT NULL,
`u_lastname` varchar(255) NOT NULL,
`u_email` varchar(255) NOT NULL,
PRIMARY KEY (`u_ref`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;
--
-- Dumping data for table `users1`
--
INSERT INTO `users1` (`u_ref`, `u_firstname`, `u_lastname`, `u_email`) VALUES
(1, 'hh', 'hh', 'hh'),
(2, 'hh', 'hhu', 'uuu'),
(3, 'hh', 'hh', 'hh'),
(4, 'hh', 'hhu', 'uuu'),
(5, 'h', 'hfgh', 'fhf'),
(6, 'h', 'f', 'jghj');
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
Create JSON:
<?php
error_reporting(0);
$conn=mysql_connect('localhost','root','1234') or die("error");
mysql_Select_db('users1',$conn);
$getdata=$_GET['fname'];
//echo $getdata;
$query="SELECT * FROM `users1` where u_firstname='".$getdata."'";
//echo $query;
$result=mysql_query($query);
$data=array();
while($row=mysql_fetch_array($result)){
array_push($data,$row);
}
echo json_encode($data);
?>
Retrieve JSON data:
<?php
$content=file_get_contents('localhost/json/index.php?fname=hh');
$data=json_decode($content);
?>
No comments:
Post a Comment
Dharamart.blogspot.in