Jump to content

output xml file from mysql record


fifin04

Recommended Posts

Hi there...

 

just a quick shoot ...Okay I know very well how to get the record from databse directly..but now my application require me to output my record as xml output....so I really need help on it.../some guide ...this is what's my xml gonna be....


<?xml version="1.0" encoding="iso-8859-1"?>
<calData>
<event type="1" year="2007" month="05" day="23" timestart="8.00 am" 

timestop="10.00 am" title="urgent meeting" detail="some explaination here"/>
<event type="1" year="2007" month="05" day="24" timestart="8.00 am" 

timestop="10.00 am" title="kickoff meeting" detail="some explaination here"/>
<event type="1" year="2007" month="05" day="25" timestart="8.00 am" 

timestop="10.00 am" title="discussion" detail="some explaination here"/>
</calData>

 

and here are my field in my database(mysql)

 

id  | type | date          | timestart  | timestop  | tittle        | detail                        |

________________________________________________________________________

 

1  | 1      | 25/05/2007 | 8.00 am  | 10.00 am  | discussion | blablabla                    |

 

 

 

Hope someone will give me some shed on light on this...thanks in advanced....

Link to comment
https://forums.phpfreaks.com/topic/51081-output-xml-file-from-mysql-record/
Share on other sites

try something like this

<?php
$output = "<?xml version='1.0' encoding='iso-8859-1'><calData>"; //removed the ? from the closing xml tag it was causing probs in here
while ($row=mysql_fetch_assoc($result)
{
$timestamp = $row['date'];
$year = date("Y", $timestamp);
$month = date("m", $timestamp);
$day = date ("d", $timestamp);
$start = $row['timestart'];
$end = $row['timestop'];
$type = $row['type'];
$title = $row['title'];
$desc = $row['detail'];

$output .= "<event type='$type' year='$year' month='$month' day='$day' timestart='$start' timestop='$end' title='$title' detail='$desc'/>";

}
$output .= "</calData>";
?>

The date isn't a unix timestamp, nor can d/m/Y format be easily converted to one.

 

Replace this

        $timestamp = $row['date'];
$year = date("Y", $timestamp);
$month = date("m", $timestamp);
$day = date ("d", $timestamp);

 

with

list ($day, $month, $year) = explode ('/', $row['date']);

 

Are you sure you want to store all the data as attributes? You'd be better off with something like

 

<calData>
     <event>
        <type>1</type>
        <date>2007-05-23</date>
        <timestart>8.00 am</timestart>
        <timestop>10.00 am</timestop>
        <title>urgent meeting</title>
        <detail>some explaination here</detail>
     </event>
</calData> 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.