PHP PHP, XML and mySQL
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: PHP, XML and mySQL

  1. #1

    PHP, XML and mySQL

    I have the following code that i am not able to get media:content to work.

    PHP Code:
    <?php 

    header
    ("Content-type: text/xml"); 

    $host "localhost"
    $user "user"
    $pass "IhaveThEanswer2012@!"
    $database "bbl_article"

    $linkID mysql_connect($host$user$pass) or die("Could not connect to host."); 
    mysql_select_db($database$linkID) or die("Could not find database."); 

    $query "SELECT * FROM links"
    $resultID mysql_query($query$linkID) or die("Data not found."); 

    $xml_output "<?xml version=\"1.0\" ?>\n"
    $xml_output .= "<channel>\n"
        
    $xml_output .= "\t\t<title>Ellucid Movies</title>\n"
        
    $xml_output .= "\t\t<link>http://comingsoon.com</link>\n"
    for(
    $x $x mysql_num_rows($resultID) ; $x++){ 
        
    $row mysql_fetch_assoc($resultID); 
    $xml_output .= "\t<item>\n"
        
    $xml_output .= "<title>" $row['name'] .".m4v" "</title>\n"
        
    $xml_output .= "<link>" $row['link'] . "</link>\n"
        
    $xml_output .= "<media:content url='" $row['local_link'] . ".m4v" "' type='video/mp4'/>\n";
        
    $xml_output .= "\t</item>\n"


    $xml_output .= "</channel>"

    echo 
    $xml_output

    ?>
    What am I doing wrong.

    Also how can I do this in DOM?

    I was able to find this
    PHP Code:
    function createUserDetailsXml(array $result) {

        
    $dom  = new DOMDocument;
        
    $dom->formatOutput TRUE// enable automatic indenting
        
    $dom->loadXML('<users/>'); // set root node

        
    foreach($result as $row) {

            
    // create user-details node
            
    $user $dom->createElement('user-details');

            
    // create and append details to user-details node
            
    $user->appendChild(
                
    $dom->createElement('user-id'$row['uid']));
            
    $user->appendChild(
                
    $dom->createElement('user-name'$row['userName']));
            
    $user->appendChild(
                
    $dom->createElement('user-points'$row['points']));
            
    $user->appendChild(
                
    $dom->createElement('image-url'$row['imageURL']));
            
    $user->appendChild(
                
    $dom->createElement('thumb-url'$row['thumbURL']));

            
    // add user-details node to XML document, e.g. users node
            
    $dom->documentElement->appendChild($user);
        };
        return 
    $dom->saveXML(); // returns the formatted XML
    }; 
    But can get it to work.

    Thanks for your help in advance.
    New to PHP and MySql. Started looking at scripts about a week ago. So far have very little understanding of it. So please be easy with me if I ask a stupid question.

    www.ethans-space.com

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,886

    Re: PHP, XML and mySQL

    For one...you're iterating the database rows incorrectly.

    PHP Code:
    while ($row mysql_fetch_assoc($resultID)) {
        ...

    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center