=php<?php
if(!$dbconnect = mysql_connect('localhost', 'root', '')) {
   echo "Connection failed to the host 'localhost'.";
   exit;
} // if
if (!mysql_select_db('test')) {
   echo "Cannot connect to database 'test'";
   exit;
} // if

$table_id = 'student';
$query = "SELECT * FROM $table_id";

$dbresult = mysql_query($query, $dbconnect);
// create a new XML document
$doc = new DomDocument('1.0');
// create root node
$root = $doc->createElement('root');
$root = $doc->appendChild($root);
// process one row at a time
while($row = mysql_fetch_assoc($dbresult)) {

// add node for each row
  $occ = $doc->createElement($table_id);
  $occ = $root->appendChild($occ);
   // add a child node for each field
  foreach ($row as $fieldname => $fieldvalue) {
  $child = $doc->createElement($fieldname);
    $child = $occ->appendChild($child);
 $value = $doc->createTextNode($fieldvalue);
    $value = $child->appendChild($value);
      } // foreach
} // while
// get completed xml document
$xml_string = $doc->saveXML();
echo $xml_string;
?>

I want this in php 4 ....
plz help me............
how can i run it php 4

I don't see anything there that wont run on PHP4, although I would change this:

$query = "SELECT * FROM $table_id";

to this:

$query = "SELECT * FROM " . $table_id;

Perhaps the problem is with your DomDocument class? You should attach the files to your post.

Matti Ressler
Suomedia

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.