473,398 Members | 2,165 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Printing complex XML from DB

Hello,
I'm retrieving database info and turning it into an xml file. The xml file has to be structured exactly like this example below:
Here is what I need:
Expand|Select|Wrap|Line Numbers
  1. <xml>
  2.  
  3. <listitem name="Video 1" url="files/flv" thumb="my_video1.jpg">
  4.  <stream name="my_video1.flv" start="0" len="-1" />
  5. </listitem>
  6.  
  7. <listitem name="Video 2" url="files/flv" thumb="my_video2.jpg">
  8.  <stream name="my_video2.flv" start="0" len="-1" />
  9. </listitem>
  10.  
  11.  
  12. <menu>
  13.  <listitem name="Video 1" />
  14.  <listitem name="Video 2" />
  15. </menu>
  16.  
  17. </xml>
Here is what I have:
[PHP]//Open Database and select All entries
$query = " SELECT * FROM `gallery` ORDER BY `order` ";
$result = mysql_query($query) or die("Could not complete database query");


//Design the XML structure
$xml ="<xml>\r";

if (mysql_num_rows($result) > 0) {
while ( $row = mysql_fetch_array($result) ) {
$xml .= "<listitem name=\"".$row["label"]."\" url=\"files/flv\" thumb=\"".$row["thumbnail"]."\">\r";
$xml .= " <stream name=\"".$row["data"]."\" start=\"0\" len=\"-1\" />\r";
$xml .= "</listitem>\r\r";
}


$xml .= "\r<menu>\r";
while ( $row = mysql_fetch_array($result) ) {
$xml .= "<listitem name=\"".$row["label"]."\" />\r";
}
}


$xml .= "</menu>\r";
$xml .= "</xml>";[/PHP]
The whole first section works perfectly but I cannot get the <menu> section to return the $row["label"]. I only need it to run back through the while loop and return the "label" for each row.
Do I need a "foreach" loop in there?

Any help would be great.
Thanks,
Mike
Oct 9 '07 #1
1 1342
I figured it out. I didn't realize I needed to run another query to get another set of results.
Here my new code if anyone ever needs soemthing like this.

[PHP]//Open Database and select All entries
$query = " SELECT * FROM `gallery` ORDER BY `order` ";
$result = mysql_query($query) or die("Could not complete database query");


//Design the XML structure, import the data and print it out
$xml ="<xml>\r\r";

if (mysql_num_rows($result) > 0) {
while ( $row = mysql_fetch_array($result) ) {
$xml .= "<listitem name=\"".$row["label"]."\" url=\"files/flv\" thumb=\"".$row["thumbnail"]."\" caption=\"".$row["caption"]."\">\r";
$xml .= " <stream name=\"".$row["data"]."\" start=\"0\" len=\"-1\" />\r";
$xml .= "</listitem>\r\r";
}
}

$xml .= "\r<menu>\r";

$query2 = " SELECT * FROM `gallery` ORDER BY `order` ";
$result2 = mysql_query($query2) or die("Could not complete database query");
while ( $row = mysql_fetch_array($result2) ) {
$xml .= " <listitem name=\"".$row["label"]."\" />\r";
}


$xml .= "</menu>\r\r";
$xml .= "</xml>";
// End XML Structure[/PHP]

This produces 2 different xml sections at the same time. One for all the data and one for a clickable menu.

Thanks
Oct 10 '07 #2

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

Similar topics

0
by: Rami | last post by:
Hello All, We have a java application including applets, servlets and ejbs. Users can get reports and print them directly from applets. Our print methods uses PrinterJob and Graphics2d, imports...
2
by: Marc Champagne | last post by:
Hi folks, I wish to print on pre-printed continuous forms on a dot matrix printer. My initial intent was to access to printer directly (in raw mode, somehow) in order to send whatever is...
0
by: JF Turcotte | last post by:
Hi I'm unsuccessfully trying to print a form's image under VB.NET. To print under .NET is a real pain in the , I find it to be complex, lenghty, confusing, upsetting and ultimately not to be...
2
by: S Shulman | last post by:
Hi I am looking for a good sample code for .NET printing Specifically I code that prints tables and populates the data into the cells Thank you, Shmuel Shulman SBS Technologies LTD
2
by: Benny | last post by:
Hello Experts, Currently I working on a web application using vs.net with C#. I require to create an invoice to a text file and print the file. I have no problem with writing to the text, but...
3
by: Chrisitiaan | last post by:
Hi, I want to develop a 'truly' object oriented application, that is, my business logic objects handle the business logic (of course) and the persistence to a MS SQL server database. The user...
2
by: Allen Davis | last post by:
I have some hierarchical data bound to a series of nested DataLists and DataGrids for which I'd like to be able to provide the end-user some targeted printing capabilities. By that I mean being...
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
3
by: Eric Layman | last post by:
Hi, If an E-coupon is limited to one person, are there ways to prevent it from printing more than once? Since on the print dialog, user can print multiple copies. Regards
7
by: Iain Wilson | last post by:
I am pulling my hair out trying to print various objects from a .net web page My apologies for cross posting but I need an answer and my previous post has attracted no interest. ASP.Net 2.0...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.