Jump to content

Outputting xml


Seth Watson

Recommended Posts

I have mysql table with Type, Month, Date, and Quantity. I am doing query, and writing to xml which will pass to chart. My error is coming because for each <row> I need to have same number of child tags. For instance, if there are six months represented in first row (<header>), I need to have six <number> tags in all the following rows, even when there may not be any Quantity for that particular month in mysql table. Right now, if a particular Type in my table doesn't show quantity for some months, than I end up with fewer <number> tags. My php is here, and xml structure below:

 

//start the XML output 
print "<chart>";
print "<chart_data>";

//output the first row that contains the years 
print "<row>";
print "<null></null>";
$category = mysql_query ("SELECT prMonth FROM table1 GROUP BY prMonth ORDER BY prDate");
for ( $column=0; $column < mysql_num_rows($category); $column++ ) {
print "<header>".mysql_result ( $category, $column, "prMonth")."</header>";
}
print "</row>";


//output row 2 to 4. Each row contains a type name and its data (Qty, Prem, Comm ...)
$series = mysql_query ("SELECT prType FROM table1 GROUP BY prType ORDER BY prType");
for ( $row=0; $row < mysql_num_rows($series); $row++ ) {
print "<row>";
$type = mysql_result ( $series, $row, "prType");
print "<string>$type</string>";

$data = mysql_query ("SELECT SUM(prQty) FROM table1 WHERE prType='$type' GROUP BY prMonth ORDER BY prDate");
for ( $column=0; $column < mysql_num_rows($data); $column++ ) {
//		Need to do something here to 
//		get number tags to show zero 
//		when there's no data for that 
//		month
	print "<number>".mysql_result($data,$column)."</number>";
}
print "</row>";
}


//finish the XML output 
print "</chart_data>";
print "</chart>";

 

 

XML structure:

 

<chart>
<chart_data>
	<row>		----this row will be the head row----
		</null>
		<header>Month name</header>
		<header>Month name</header>
		...
	</row>
	<row>		----this row will start body rows----
		<string>Type name</string>
		<number>total quantity for month, for this type</number>
		<number>total quantity for month, for this type</number>
		...
	</row>
	...
</chart_data>
</chart>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.