I recently asked this question, XML structure while creating from MySQL query in PHP. I got the answer I needed but now I have a similar case that is missing just one thing.
I duplicated the code and changed as needed but the category rows are not working.
Here is my code
$xml2 = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$xml2 .= "
";
$xml2 .= "<resources>";
$xml2 .= "<version>1</version>";
$xml2 .= "
";
//select all items in table
$sql2 = "SELECT distinct category, name FROM user where user = '$user' and category is not null order by category";
$result2 = mysql_query($sql2);
if (!$result2) {
die('Invalid query: ' . mysql_error());
}
if(mysql_num_rows($result2)>0){
while($row2 = mysql_fetch_assoc($result2)){
if(!isset($previousRow2) || !isset($previousRow2["category"]) || $previousRow2["category"] != $row2["category"])
{
$xml2 .= "
";
$xml2 .= "<category title=\"" . $row["category"] . "\" />
";
}
$xml2 .= "<item drawable=\"";
$xml2 .= $row2["name"];
$xml2 .= "\" />";
$xml2 .= "
";
$previousRow2 = $row2;
}
}
$xml2 .= "</resources>";
This is outputting this
<category title="" />
<item drawable="bigdx_clean" />
<category title="" />
<item drawable="bluetooth" />
<item drawable="bluetooth_audio" />
<item drawable="browser" />
<item drawable="calculator" />
<item drawable="calendar" />
<item drawable="call_history" />
<item drawable="camera" />
The titles are blank though.
I'm using the same concept of the working code from other question. It's a different query so I must have something wrong with it?
$xml2 .= "<category title=\"" . $row["category"] . "\" />
";