fifin04 Posted May 12, 2007 Share Posted May 12, 2007 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.... Quote Link to comment https://forums.phpfreaks.com/topic/51081-output-xml-file-from-mysql-record/ Share on other sites More sharing options...
paul2463 Posted May 12, 2007 Share Posted May 12, 2007 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>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/51081-output-xml-file-from-mysql-record/#findComment-251434 Share on other sites More sharing options...
Barand Posted May 12, 2007 Share Posted May 12, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/51081-output-xml-file-from-mysql-record/#findComment-251499 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.