473,503 Members | 1,701 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

simple xml and php

65 New Member
Hi all,

im a little bit puzzled with this one.

Im after creating a simplexml encoded file using php, which calls from a mysql database.

i have the following, but i dont see what is wrong with the syntax.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. require_once("connect.inc.php");
  3.    $db = getConnectionMySql();
  4.    $stmt = $db->query("SELECT email, name, lastlogin FROM subscriber");
  5.    while ( $obj = $stmt->fetchObject()){
  6.        echo $obj->email . ":" . $obj->name . ":" . $obj->lastlogin .  "<br />";
  7.        //   print " <row>\n";
  8.       // print "  <email>$email</email>\n";
  9.        //print "  <name>$name</name>\n";
  10.        //print " <lastlogin>$lastlogin</lastlogin>\n";
  11.        //print " </row>\n";
  12.    }
  13.  
  14.    $fp = fopen('subscribers.xml','w');
  15.     if(!$fp) {
  16.     die('Error cannot create XML file');
  17. }
  18. fwrite($fp,$stmt());
  19. //fwrite( $fp, implode(”,$obj));
  20. fclose($fp);
  21. echo "XML has been written.  <a href=\"subscribers.xml\">View the XML.</a>";
  22.  
  23. ?>
  24.  
Nov 16 '09 #1
3 1869
Dormilich
8,658 Recognized Expert Moderator Expert
I could probably tell you something, if I knew what you were doing. there are no error messages told, neither is anything related to the objects you use. All I can say right now is that there is no XML root element.
Nov 17 '09 #2
whitep8
65 New Member
Hi,

Ive had another look and I can see ive missed some major stuff.

I know i should have created a root and some parent child data etc.

Ive created the following, with the following error

Parse error: syntax error, unexpected '=' in /Applications/MAMP/htdocs/CG0119/subscribelist.php on line 15

here is the code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. include_once("connect.inc.php");
  3.   $db = getConnectionMySql();
  4.    $stmt = $db->query("SELECT email, name, lastlogin FROM subscriber");
  5.    while ( $obj = $stmt->fetchObject()){
  6.        echo $obj->email . ":" . $obj->name . ":" . $obj->lastlogin .  "<br />";
  7.        //   print " <row>\n";
  8.       // print "  <email>$email</email>\n";
  9.        //print "  <name>$name</name>\n";
  10.        //print " <lastlogin>$lastlogin</lastlogin>\n";
  11.        //print " </row>\n";
  12.    }
  13.  
  14. $doc = new DomDocument('1.0'); 
  15. root=$doc->createElement('subscribers');
  16. $root = $doc->appendChild($root);  
  17. while($row = mysql_fetch_assoc($result))
  18. {
  19.     // add node for each record
  20.     $email= $doc->createElement('email');
  21.     $email = $root->appendChild($email);
  22. }  
  23. foreach($row as $fieldname => $fieldvalue)
  24. {
  25.     $child = $doc->createElement($fieldname);
  26.     $child = $email->appendChild($child);
  27.     //add data to the new element
  28.     $value = $doc->createTextNode($fieldvalue);
  29.     $value = $child->appendChild($value);
  30. }  
  31. echo 'Wrote: ' . $doc->save("subscribers.xml") . '  bytes';  
  32. ?>
  33.  
Nov 17 '09 #3
Dormilich
8,658 Recognized Expert Moderator Expert
@whitep8
$ missing.

Expand|Select|Wrap|Line Numbers
  1. $email = $root->appendChild($email);
  2. // does the same as
  3. $root->appendChild($email);
but you don’t define the text content of that node…
Nov 17 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
6065
by: delisonews | last post by:
I'm looking for a simple, filesystem-based message board. (No MySQL!) Something that I could include easily in my code: include '../inc/messageboard.php'; .... so that the board shows up at...
3
3659
by: Patchwork | last post by:
Hi Everyone, Please take a look at the following (simple and fun) program: //////////////////////////////////////////////////////////////////////////// ///////////// // Monster Munch, example...
8
6477
by: Dan | last post by:
Using XML::Simple in perl is extreemly slow to parse big XML files (can be up to 250M, taking ~1h). How can I increase my performance / reduce my memory usage? Is SAX the way forward?
6
2048
by: Manuel Collado | last post by:
I would like to write simple, yet well structured documents with a really simple XML DTD (or schema). Either Docbook or SDocbook are overkill for this simple case. XHTML is simpler, but...
11
2676
by: JKop | last post by:
Take the following simple function: unsigned long Plus5Percent(unsigned long input) { return ( input + input / 20 ); } Do yous ever consider the possibly more efficent:
4
2084
by: Steven Blair | last post by:
I have the following number: 64521234567890 and need to apply some sort of simple encryption. Does c# have any classes for doing this. I cant use 3DES or anything as complex as. The size...
7
2265
by: abcd | last post by:
I am trying to set up client machine and investigatging which .net components are missing to run aspx page. I have a simple aspx page which just has "hello world" printed.... When I request...
24
6285
by: firstcustomer | last post by:
Hi, Firstly, I know NOTHING about Javascript I'm afraid, so I'm hoping that someone will be able to point me to a ready-made solution to my problem! A friend of mine (honest!) is wanting to...
14
2959
by: Giancarlo Berenz | last post by:
Hi: Recently i write this code: class Simple { private: int value; public: int GiveMeARandom(void);
10
2105
by: Phillip Taylor | last post by:
Hi guys, I'm looking to develop a simple web service in VB.NET but I'm having some trivial issues. In Visual Studio I create a web services project and change the asmx.vb file to this: Imports...
0
7074
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7273
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7322
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6982
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5572
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5000
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3150
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1501
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
374
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.