DevelopPHP
home gear home donate
Search Results For
in:

Libraries book

HTML Library CSS Library JavaScript Library PHP Library

Videosbook

PHP and MySQL JavaScript HTML and CSS Vector and 3D Flash Actionscript Android Dev Miscellaneous

Resourcesbook

Website Hosting Developer Q+A
Discover Magic XML File Rendering for MySQL database results in PHP   Share / Like
This script corresponds with the following video tutorial about rendering XML files according to MySQL database results using PHP: 
http://www.developphp.com/view.php?tid=740

Please view the video for maximum understanding... here is the script used in the video:


Learn HTML
<?php
// PHP file that renders perfect Dynamic XML for MySQL Database result sets
// Script written by Adam Khoury @ www.developphp.com - April 05, 2010
// View the video that is tied to this script for maximum understanding
// -------------------------------------------------------------------
header("Content-Type: text/xml"); //set the content type to xml
// Initialize the xmlOutput variable
$xmlBody '<?xml version="1.0" encoding="ISO-8859-1"?>';
$xmlBody .= "<XML>";
// Connect to your MySQL database whatever way you like to here
mysql_connect("DB_HostName","DB_UserName","DB_Password") or die (mysql_error());
mysql_select_db("DB_Name") or die ("no database");
// Execute the Query on the database to select items(20 in this example)
$sql mysql_query("SELECT * FROM my_table ORDER BY date_time DESC LIMIT 0, 20");
while(
$row mysql_fetch_array($sql)){
    
// Set DB variables into local variables for easier use 
    
$id $row["id"]; 
    
$title $row["title"];  
    
$date_time strftime("%b %d, %Y"strtotime($row["date_time"])); 
    
$description $row["description"];  
    
// Start filling the $xmlBody variable with looping content here inside the while loop 
    // It will loop through 20 items from the database and render into XML format
    
$xmlBody .= '
<Data> 
    <DataID>' 
$id '</DataID> 
    <DataTitle>' 
$title '</DataTitle>
    <DataDate>' 
$title '</DataDate>
    <DataDescr>' 
$description '</DataDescr>
</Data>'
;
// End while loop
mysql_close(); // close the mysql database connection
$xmlBody .= "</XML>";
echo 
$xmlBody// output the gallery data as XML file for flash
?>

Home   •   Terms of Use   •   T-Shirts   •   RSS   •   Testimonials   •   Subscribe   •   Classroom Chalkboard   •   Developer Q+A   •   Donate   •   Top ↑
Popular In PHP / MySQL E-Commerce Store Production
Social Network Website Building
Image Upload / Photo Processing
CMS Software Programming
Mass Email Systems
Magic XML Data
Search Programming
Popular In JavaScript JSON Programming
Ajax Programming
Animating Elements
WYSIWYG Programming
Date/Time Programming
DOM Scripting
Object Reference
Popular In HTML Canvas Element
New Form Elements
Audio Element
Video Element
Drag and Drop
Event Handling
Element Grouping
Popular In CSS Custom Font Embedding
Dynamic Fit Backgrounds
Theatre Mode
Box Overlays
CSS Level 1 Properties
CSS Level 2 Properties
CSS Level 3 Properties
DevelopPHP.com is a growing educational system packed with video and written material that you can access 24/7 100% free. The focus here in 2013 is spread between five technologies: HTML, CSS, JavaScript, PHP and MySQL. Learn programming theory, database interaction, web design, animation, graphics editing, vector art, 3D modeling, and much more. The educational experience here is a hybrid one offering both high quality video tutorials and code libraries that grow more robust every day. The code libraries are being assembled so that developers can discover all of the building blocks of their favorite languages. The libraries coupled with high quality video tutorials will take you deep down the rabbit hole very quickly. You can also ask questions and get free advice at WebIntersect.com.
©2014 DevelopPHP.com HTML5