Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    167

    how to fetch data from mysql to xml file using php

    Hi there

    i have 1 file ( index.php ) and one table in database

    the table structure is : ( ID , Name , Phone )

    i want to fetch this data to xml file look like that :

    <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
    <string>
    1|Adam|100001
    </string>
    <string>
    1|Calaman|100001
    </string>
    <string>
    1|Serah|100001
    </string>
    </ArrayOfString>

    i want to php code to select the data and the show it on xml file .

    can you please tell me how can i do this ?

    Thank you
    Attached Thumbnails Attached Thumbnails Untitled.png  

  2. #2
    Join Date
    Sep 2009
    Posts
    167
    i'am still need help .

  3. #3

    *

    Not pretty, but it's close:



    mysql_connect($dbhost, $dbuser, $dbpass);
    @mysql_select_db($dbschema);

    $query = "select ID, NAME, PHONE, from table_name";

    $result = mysql_query($query);

    $i = 0;

    print "<ArrayOfString">\n";

    while ($i < mysql_numrows($result)) {
    print "<string>\n";
    print mysql_result($result,$i,"ID") . "|";
    print mysql_result($result,$i,"ID") . "|";
    print mysql_result($result,$i,"ID") . "\n";
    print "</string>\n"

    $i++;
    }

    print "</ArrayOfString>\n";



    May the force be with you.

  4. #4
    Join Date
    Sep 2009
    Posts
    167
    Quote Originally Posted by nickelsack View Post
    Not pretty, but it's close:



    mysql_connect($dbhost, $dbuser, $dbpass);
    @mysql_select_db($dbschema);

    $query = "select ID, NAME, PHONE, from table_name";

    $result = mysql_query($query);

    $i = 0;

    print "<ArrayOfString">\n";

    while ($i < mysql_numrows($result)) {
    print "<string>\n";
    print mysql_result($result,$i,"ID") . "|";
    print mysql_result($result,$i,"ID") . "|";
    print mysql_result($result,$i,"ID") . "\n";
    print "</string>\n"

    $i++;
    }

    print "</ArrayOfString>\n";



    May the force be with you.

    thank you man for your help ,

    but i think this will not export it xml file

  5. #5
    I guess I need to know more about how you're trying to do it.

    Perhaps you need to change the headers to tell the client you're sending xml. Put this at the top of your php:


    header ("Content-Type:text/xml");

Similar Threads

  1. Extracting data from XML file by PHP
    By tarsius in forum Programming Discussion
    Replies: 4
    Last Post: 10-13-2011, 01:48 AM
  2. PHP, reading from an xml file
    By Shib in forum Programming Discussion
    Replies: 2
    Last Post: 06-21-2010, 03:03 PM
  3. PHP, Mysql Fetch Error Help
    By pcnet21 in forum Programming Discussion
    Replies: 5
    Last Post: 08-18-2006, 01:31 PM
  4. inserting data to mysql using php..from file?
    By SFA-Dark in forum Programming Discussion
    Replies: 3
    Last Post: 01-26-2005, 02:21 AM
  5. Fetch info off a website and put it into a database - PHP/MYSQL
    By mrsam in forum Employment / Job Offers
    Replies: 4
    Last Post: 10-31-2004, 04:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •