SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Thread: Xml And Php

  1. #1
    SitePoint Enthusiast ethe's Avatar
    Join Date
    Oct 2005
    Posts
    56
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Xml And Php

    I have this code:

    testxml.php
    PHP Code:
    header("Content-type: text/xml");
    $sql ="SELECT * FROM `Ouder` WHERE `OuderId` =30966";
    $result=mysql_query($sql);
    $datateller=mysql_num_fields($result);
    print
    "";
    while(
    $rowmysql_fetch_array($result)){
        print
    "";
            for(
    $i=0$i$datateller$i++){
            
    $tag=mysql_field_name($result$i);
            print 
    "<$tag>".$row[$i]."";
            } 
        print 
    "";

    Xml returns me with the error that there is no element found some one please help

  2. #2
    SitePoint Wizard silver trophy kyberfabrikken's Avatar
    Join Date
    Jun 2004
    Location
    Copenhagen, Denmark
    Posts
    6,157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't got a document-element, which you must have in xml. You also haven't got a header, and your tags aren't enclosed.

    Try this.
    PHP Code:
    header("Content-type: text/xml");
    $sql ="SELECT * FROM `Ouder` WHERE `OuderId` =30966";
    $result=mysql_query($sql);
    $datateller=mysql_num_fields($result);
    echo "<?xml version='1.0' ?>";
    echo "<root>";
    while($row= mysql_fetch_array($result)){
        echo "<row>";
            for($i=0; $i< $datateller; $i++){
                $tag=mysql_field_name($result, $i);
                echo "<$tag>".htmlspecialchars($row[$i])."</$tag>";
            } 
        echo "</row>";
    }
    echo "</root>";
    The regular php-forum is better suited for theese types of questions.


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
  •