SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2006
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    output xml file from mysql record using php

    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....
    Code:
    <?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....

  2. #2
    That's Right. notepad_coder's Avatar
    Join Date
    Apr 2002
    Location
    Colorado
    Posts
    835
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    header("Content-Type: application/xml");
    echo 
    "<"."?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n";
    echo 
    "<calData>\n";
    $result mysql_query("SELECT * FROM cal");
    while (
    $row mysql_fetch_object($result)) {
        
    $date = array("day" => substr($row->date02), "month" => substr($row->date32), "year" => substr($row->date64));
        echo 
    "\t<event type=\"".$row->type."\" year=\"".$date['year']."\" month=\"".$date['month']."\" day=\"".$date['day']."\" timestart=\"".$row->timestart."\" timestop=\"".$row->timestop."\" title=\"".$row->title."\" detail=\"".$row->detail."\" />\n";
    }
    echo 
    "</calData>\n"
    That should do it for your syntax.. Here's something just like this that I'm working on for an example:
    PHP Code:
        private function generateDay($stamp 0) {
            if (
    $stamp != 0) {
                echo 
    "\t\t<day datetime=\"".$this->formatStamp($stamp)."\">\n";
                if (
    $this->getEvents($stamp1) == 0) {
                    echo 
    "\t\t\t<events count=\"0\" />\n";
                } else {
                    echo 
    "\t\t\t<events count=\"".$this->getEvents($stamp1)."\">\n";
                    
    $this->getEvents($stamp);
                    echo 
    "\t\t\t</events>\n";
                }
                echo 
    "\t\t</day>\n";
            } else {
                echo 
    "\t\t<day datetime=\"0\" />\n";
            }
        }
        private function 
    getEvents($stamp$count 0) {
            
    $result mysql_query("SELECT * FROM gimpcal_events WHERE eventdate='".$this->formatStamp($stamp1)."' AND username='".$this->user."' ORDER BY eventtime ASC");
            if (
    $count == 1) {
                return 
    mysql_num_rows($result);
            } else {
                if (
    mysql_num_rows != 0) {
                    while (
    $row mysql_fetch_object($result)) {
                        if (
    $row->eventtime == 0) {
                            
    $eventtime 0;
                        } else {
                            
    $eventtime $this->formatStamp($row->eventime);
                        }
                        echo 
    "\t\t\t\t<event time=\"".$eventtime."\">\n";
                        echo 
    "\t\t\t\t\t<title><![CDATA[".$row->title."]]></title>\n";
                        echo 
    "\t\t\t\t\t<information>\n";
                        echo 
    "\t\t\t\t\t\t<![CDATA[".$row->information."]]>\n";
                        echo 
    "\t\t\t\t\t</information>\n";
                        echo 
    "\t\t\t\t</event>\n";
                    }
                } else {
                    return 
    0;
                }
            }
        } 
    - the lid is off the maple syrup again!


Bookmarks

Posting Permissions

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