Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Old 05-26-2009, 10:19 PM XML database
Junior Talker

Posts: 4
Name: Alex
Trades: 0
Hi,

I was wondering how would you display articles with an XML database. So far I figured out the code
PHP Code:
<?php
$title 
"";
?>
<?php
require 'header.php';
?>
<div align="center"><div id="games">
hello
</div>

<div id="news">
<script type="text/javascript">
xmlDoc=loadXMLDoc("news.xml");

document.write("<h2>" + xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue + "</h2>");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue + "<br>" + "<br>");
document.write(xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue + "<br>" + "<br>");

</script>
</div>
<?php
require 'footer.php';
?>
but this only displays one article. How would I make it display let's say five? and if you could could you explain why. I'm still new to it an am trying to learn, so I'd like an explanation.

Thanks
detroitredwings is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 05-26-2009, 11:20 PM Re: XML database
Decaf's Avatar
Ultra Talker

Posts: 489
Name: Adam
Trades: 0
Place it in a loop.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Decaf is offline
Reply With Quote
View Public Profile Visit Decaf's homepage!
 
Old 05-27-2009, 04:47 PM Re: XML database
Junior Talker

Posts: 4
Name: Alex
Trades: 0
Thanks for the reply. Are you telling me to do something like this...

PHP Code:
<script type="text/javascript">
xmlDoc=loadXMLDoc("news.xml");

document.write("<h2>" xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue "</h2>");
document.write(xmlDoc.getElementsByTagName("author")[0].childNodes[0].nodeValue "<br>" "<br>");
document.write(xmlDoc.getElementsByTagName("message")[0].childNodes[0].nodeValue);
</script>
<p><br></p>
<script type="text/javascript">
xmlDoc=loadXMLDoc("news.xml");

x=xmlDoc.getElementsByTagName("title");
for (i=0;i<x.length;i++)
  {
  document.write("<h2>");
  document.write(x[i].childNodes[0].nodeValue);
  document.write("</h2>");
  } 
x=xmlDoc.getElementsByTagName("author");
for (i=0;i<x.length;i++)
  {
  document.write(x[i].childNodes[0].nodeValue);
  document.write("<br>");
  document.write("<br>");
  } 
x=xmlDoc.getElementsByTagName("message");
for (i=0;i<x.length;i++)
  {
  document.write(x[i].childNodes[0].nodeValue);
  document.write("<br>");
  } 
</script> 
This only works if I have only two articles in my XML file. If I have more than two it shows the titles, authors, and messages together. Like I said, I'm really new to XML and am still trying to learn. The w3schools tutorial isn't very clear. If you could show me some code with an explanation on why that's the code you came up with it would be great.

Thanks
detroitredwings is offline
Reply With Quote
View Public Profile
 
Old 05-29-2009, 06:48 PM Re: XML database
Junior Talker

Posts: 4
Name: Alex
Trades: 0
anybody know how to fix this?
detroitredwings is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to XML database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24895 seconds with 12 queries