Friday, 4 April 2014

Code to Preview XML file using PHP and MYSQL in browser for Mobile APPS Web Services

1. Make a database in phpmyadmin

 2. Make a table with your requred field.

 3. And then wirte code to make xml file in php for table which is in database.
Here you can find the code please click below
DEMO



 Here below have code as well as example :


1. Database "practise" and select

2. Save the below code as "practise.sql" and Import it to database "practise"

-- phpMyAdmin SQL Dump
-- version 3.4.10.1deb1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Apr 04, 2014 at 03:31 PM
-- Server version: 5.5.35
-- PHP Version: 5.3.10-1ubuntu3.10

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: `practise`
--

-- --------------------------------------------------------

--
-- Table structure for table `contacts`
--

CREATE TABLE IF NOT EXISTS `contacts` (
  `contact_id` int(11) NOT NULL AUTO_INCREMENT,
  `contact_first` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_last` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_designation` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_email` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_gender` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_address` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contact_phone` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  PRIMARY KEY (`contact_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=40 ;

--
-- Dumping data for table `contacts`
--

INSERT INTO `contacts` (`contact_id`, `contact_first`, `contact_last`, `contact_designation`, `contact_email`, `contact_gender`, `contact_address`, `contact_phone`) VALUES
(39, 'ritu', 'raj', 'Sr. Testing Engineer', 'ritu.raj@abc.com', 'Male', 'Delhi', '123456789'),
(38, 'raj', 'ritu', 'Designer', 'ritu.raj@abc.com', 'male', 'Delhi', '123456796'),
(30, 'Ritu', 'Raj', 'Software Developer', 'ritu.raj@abc.com', 'Male', 'Delhi', '8285431670');

/*!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 */;




Here You Can Find The Code



XML.php

<?php header('Content-type: application/xml');echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
 mysql_connect('localhost', 'root', 'root');
 mysql_select_db('practise') or die('connection error');
 $query = "Select * From contacts Order By contact_id DESC";
   $res1   = mysql_query($query);
   echo '<abc_employees>';
   while($row = mysql_fetch_array($res1))
    {
    ?>
      <records>
        <id><?php echo $row['contact_id']; ?></id>
        <first-name><?php echo $row['contact_first']; ?></first-name>
        <last-name><?php echo $row['contact_last']; ?></last-name>
        <designation><?php echo $row['contact_designation']; ?></designation>
        <email><?php echo $row['contact_email']; ?></email>
        <gender><?php echo $row['contact_gender']; ?></gender>
        <address><?php echo $row['contact_address']; ?></address>
        <phone><?php echo $row['contact_phone']; ?></phone>
        </records>
   <?php
   }
  ?>
  </abc_employees>


  And Run XML.php on localhost



No comments:

Post a Comment

Printing first 50 Fibonacci numbers Using PHP Program

Fibonacci series is a series of numbers in which each number is the sum of the two preceding numbers. For example. 0 , 1 , 1 , 2 , 3 , 5...