PlainDonut Report post Posted January 17, 2008 Boy have I stayed up late trying to figure this one out. I hope someone can help me because I was getting meaner by the hour for anyone who approached me. Here's what I'm trying to do... I have a database query of clients, remaining licenses, used licenses and enrolled. When I try to format the XML data I can't seem to group them correctly. I believe it is because of my lack of knowledge on php mysql arrays. I'm a quick learner though. Here is what the correct XML output should look like: <chart caption="[b]License Usage Report[/b]" subcaption="[b]by Client[/b]" palette="[b]1[/b]"> <categories> <category label="[b]Clients1[/b]" /> <category label="[b]Client2[/b]" /> <category label="[b]Client3[/b]" /> </categories><dataset SeriesName="[b]Licenses Remaining[/b]"> <set value="[b][/b]" /> <set value="[b]129[/b]" /> <set value="[b]72[/b]" /> </dataset><dataset SeriesName="[b]Used Licenses[/b]"> <set value="[b][/b]" /> <set value="[b]283[/b]" /> <set value="[b]0[/b]" /> </dataset><dataset SeriesName="[b]Students Enrolled[/b]"> <set value="[b][/b]" /> <set value="[b]120[/b]" /> <set value="[b]0[/b]" /> </dataset> </chart> Share this post Link to post Share on other sites
PlainDonut Report post Posted January 17, 2008 OK, well I figured out how to do it dirty. I'm wondering if someone can help me clean this code up a bit? <?php header("Content-type: text/xml" ); $host = "localhost"; $user = "root"; $pass = "password" ; $database = "database"; $linkID = mysql_connect($host, $user , $pass) or die("Could not connect to host."); mysql_select_db ($database, $linkID) or die("Could not find database." ); $query = "SELECT accounts.name AS "Client", accounts_cstm.remaininglicenses_c AS "RemainingLicenses", accounts_cstm.usedlicenses_c AS "UsedLicenses", accounts_cstm.studentsenrolled_c AS "StudentsEnrolled" FROM accounts_cstm INNER JOIN accounts ON accounts_cstm.id_c = accounts.id WHERE (((accounts_cstm.remaininglicenses_c)>"0") AND ((accounts.deleted)=0));"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<chart caption="License Usage Report" subcaption="by Client" palette="1">"; $xml_output .= "t<categories>"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "tt<category label="" . $row['Client'] . "" />"; } $xml_output .= "t</categories>"; //GET LICENSES REMAINING $query = "SELECT accounts.name AS "Client", accounts_cstm.remaininglicenses_c AS "RemainingLicenses", accounts_cstm.usedlicenses_c AS "UsedLicenses", accounts_cstm.studentsenrolled_c AS "StudentsEnrolled" FROM accounts_cstm INNER JOIN accounts ON accounts_cstm.id_c = accounts.id WHERE (((accounts_cstm.remaininglicenses_c)>"0") AND ((accounts.deleted)=0));"; $resultID2 = mysql_query($query, $linkID) or die("Data not found."); $xml_output .= "t<dataset SeriesName="Licenses Remaining">"; for($y = 0 ; $y < mysql_num_rows($resultID2) ; $y++){ $rowy = mysql_fetch_assoc($resultID2); $xml_output .= "tt<set value="" . $rowy['RemainingLicenses'] . "" />"; } $xml_output .= "t</dataset>"; //GET USED LICENSES $query = "SELECT accounts.name AS "Client", accounts_cstm.remaininglicenses_c AS "RemainingLicenses", accounts_cstm.usedlicenses_c AS "UsedLicenses", accounts_cstm.studentsenrolled_c AS "StudentsEnrolled" FROM accounts_cstm INNER JOIN accounts ON accounts_cstm.id_c = accounts.id WHERE (((accounts_cstm.remaininglicenses_c)>"0") AND ((accounts.deleted)=0));"; $resultID2 = mysql_query($query, $linkID) or die("Data not found."); $xml_output .= "t<dataset SeriesName="Used Licenses">"; for($y = 0 ; $y < mysql_num_rows($resultID2) ; $y++){ $rowy = mysql_fetch_assoc($resultID2); $xml_output .= "tt<set value="" . $rowy['UsedLicenses'] . "" />"; } $xml_output .= "t</dataset>"; //GET STUDENTS ENROLLED $query = "SELECT accounts.name AS "Client", accounts_cstm.remaininglicenses_c AS "RemainingLicenses", accounts_cstm.usedlicenses_c AS "UsedLicenses", accounts_cstm.studentsenrolled_c AS "StudentsEnrolled" FROM accounts_cstm INNER JOIN accounts ON accounts_cstm.id_c = accounts.id WHERE (((accounts_cstm.remaininglicenses_c)>"0") AND ((accounts.deleted)=0));"; $resultID2 = mysql_query($query, $linkID) or die("Data not found."); $xml_output .= "t<dataset SeriesName="Students Enrolled">"; for($y = 0 ; $y < mysql_num_rows($resultID2) ; $y++){ $rowy = mysql_fetch_assoc($resultID2); $xml_output .= "tt<set value="" . $rowy['StudentsEnrolled'] . "" />"; } $xml_output .= "t</dataset>"; $xml_output .= "t</chart>"; echo $xml_output; ?> Share this post Link to post Share on other sites