SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: xml

  1. #1
    SitePoint Enthusiast paddysteed's Avatar
    Join Date
    May 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    xml

    I made some code:

    PHP Code:
                    header('Content-type: text/xml');
                    
                    if(!isset($_GET['orderdirection']))
                    {
                        $orderdirection = 'ASC';
                    }
                    else
                    {
                        $orderdirection = $_GET['orderdirection'];
                    }
                    
                    if(!isset($_GET['orderby']))
                    {
                        $orderby = 'datedue';
                    }
                    else
                    {
                        $orderby = $_GET['datedue'];
                    }
                    
                    $xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
                    
    $sql 'SELECT * FROM `homework` WHERE `dategiven` = \'' $GET_['date'] . '\' OR `datedue` = \'' $GET_['date'] . '\' OR `datestobedone` LIKE \'%' $GET_['date'] . '%\' ORDER BY `homework`.`' $orderby '` ' $orderdirection ' ';
                    
    $result mysql_query($sql) or die(mysql_error());
                    while(
    $row mysql_fetch_array($result) or die (mysql_error()))
                    {
                        
    $xml .= '<homework>';
                        
    $xml .= '<datedue>' $row['datedue'] . '</datedue>';
                        
    $xml .= '<dategiven>' $row['dategiven'] . '</dategiven>';
                        
    $xml .= '<description>' $row['description'] . '</description>';
                        
    $xml .= '<expectedtimetodo>' $row['expectedtimetodo'] . '</expectedtimetodo>';
                        
    $xml .= '<done>' $row['done'] . '</done>';
                        
    $xml .= '<subject>' $row['subject'] . '</subject>';
                        
    $xml .= '</homework>';
                    }
                    echo 
    $xml;
    but when i go on it 'date=2008-02-19' it doesn't echo anything eaven the <?xml version="1.0 "?> does anyone know what is wrong

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    In this line while($row = mysql_fetch_array($result) or die (mysql_error())) you can eliminate the 'or die...' part.
    If it doesn't even show the <?xml part, it obviously doesn't get that far. If you don't get a mysql error, then the problem might lie in the header line. Take that away and see if you get any output.

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paddysteed View Post
    but when i go on it 'date=2008-02-19' it doesn't echo anything eaven the <?xml version="1.0 "?> does anyone know what is wrong
    Do you have display_errors set to on in php.ini?

    If display_errors is off, then an parse error will cause your screen to come back blank with no output.

    However, as was pointed out, the die() statement makes the script stop executing before you get to the actual outputting part. You could try using die($xml) - that way, you'll see what's already been stored in xml before the error occurred.

    Also, should there be an "or die()" in the while statement? It seems to me that that would simply cause the site to stop executing at some point. As soon as that evaluates, you're program ends - even if there is no mysql_error.

    - Walkere

  4. #4
    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)
    The syntax highlighting gives it away. Look at the line:
    PHP Code:
    $xml = "<?xml version="1.0\" encoding=\"UTF-8\"?>\n";
    If you don't see it, look again.

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2008
    Posts
    83
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by kyberfabrikken View Post
    The syntax highlighting gives it away. Look at the line:
    PHP Code:
    $xml = "<?xml version="1.0\" encoding=\"UTF-8\"?>\n";
    If you don't see it, look again.
    In other words, your script wasn't working because of a simple parse error.

    If you're going to be testing out new scripts like this, I'd highly suggest putting display_errors on in your php.ini file or an .htaccess file. Makes it much easier to locate silly errors like this.

    - Walkere


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
  •