bdmovies Posted July 1, 2008 Share Posted July 1, 2008 Hi, Debated whether or not to put this in the OOP section, decided to put it here, because I don't think the OOP is the problem. I am trying to create a page (xml_creator.php) that dynamically creates XML on the fly for my pages. For example: Manager wants to view a list of all the employees, so he goes to the employees.php which calls xml_creator.php?table_name=employees xml_creator.php then takes the table_name value and uses that to query that table as well as make the 2nd level node for the xml... <root> <$table_name> <employee_id> etc etc </$table_name> </root> The idea is that (not necessarily w/ the employees page) some pages will have multiple data sets needed and therefore will need a new instance of the xml_create function...I'll just post the code and the error.... xml_create.php; <?php require_once 'connectDB.class.php'; class create_xml extends DBconnector { function create_xml() { $settings = new SystemComponent(); $connect = new DBconnector(); $table_name = $_POST['table_name']; // Query the database and get all the records from the Images table $query = 'SELECT * FROM $table_name'; $result = $connect->queryDB($query); $row = $connect->fetchArray($result); $totalRows = $connect->numRows($result); $connect->closeDB(); // Send the headers header('Content-type: text/xml'); header('Pragma: public'); header('Cache-control: private'); header('Expires: -1'); echo '<?xml version="1.0" encoding="utf-8"?>'; echo '<root>'; if ($totalRows > 0) { // Show if recordset not empty do { echo "<$table_name>"; foreach ($row as $column=>$value) { echo "<$column>$row[$column]</$column>"; } echo "</$table_name>"; } while ($row = mysql_fetch_assoc($result)); } // Show if recordset not empty echo "</root>"; return; } //Close function } //close class $create_xml = new create_xml(); mysql_free_result($rsImages); ?> This shows the following: This page contains the following errors: error on line 1 at column 46: Extra content at the end of the document Below is a rendering of the page up to the first error. However, the source of that page says <?xml version="1.0" encoding="utf-8"?><root></root><br /> <b>Catchable fatal error</b>: Object of class create_xml could not be converted to string in <b>/***/support/XmlCreator.php</b> on line <b>42</b><br /> Link to comment https://forums.phpfreaks.com/topic/112704-creating-xml-through-oop-php/ Share on other sites More sharing options...
bdmovies Posted July 1, 2008 Author Share Posted July 1, 2008 bump Link to comment https://forums.phpfreaks.com/topic/112704-creating-xml-through-oop-php/#findComment-579263 Share on other sites More sharing options...
DarkWater Posted July 1, 2008 Share Posted July 1, 2008 Okay, you completely defeat the purpose of OOP if you just put completely unrelated functions into the same class. It would be simpler to do it procedurally at this point, unless you seriously rethink your logic. Link to comment https://forums.phpfreaks.com/topic/112704-creating-xml-through-oop-php/#findComment-579357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.