0
=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

2
Contributors
1
Reply
2
Views
9 Years
Discussion Span
Last Post by Suomedia
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.