Hey everyone!
I come seeking advice as I'm not primarily a php dev. I work mostly
with Flash Actionscript but am able to make my way around php (some
cut & paste) to get my needed results.
I'm stumped right now and can't seem to figure out the best solution
for my project.
I'm using PHP to read mySQL and output XML. I've done this in the past
with success but this time I need to format the XML a certain way.
The XML should look like this:
<node label='&#65533; Retail' value='1'>
   //undetermined amount of nodes here
   <node label="label name" data="dataHere" />
</node>
<node label='&#65533; Home' value='2'>
   //undetermined amount of nodes here
   <node label="label name" data="dataHere" />
</node>
...etc for about 10 categories.

Below is the php that I'm trying to rework. I built this from a
previous piece of code that I acquired then reworked.

<code>
 <?php
header("Content-type: text/xml");
// ** MySQL settings ** //

$host = "localhost";
$user = "username";
$pass = "password";
$database = "dbname";
$table = "videos";

$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 * FROM $table";

$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";

//auto
$xml_output .= "<node label='» Auto' value='1'>\n";
for($x = 0 ; $x < mysql_num_rows($resultID); $x++){
   $row = mysql_fetch_assoc($result);
        if ($row['cat'] == 'auto'){
    $xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] .  "' data='" . $row['file'] . "'></vid>\n";

        }
        
}
$xml_output .= "</node>";

//retail
$xml_output .= "<node label='» Retail' value='2'>\n";
for($z = 0 ; $z < mysql_num_rows($resultID); $z++){
  $row = mysql_fetch_assoc($result);
        
        if ($row['cat'] == 'retail'){
     $xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] .  "' data='" . $row['file'] . "'></vid>\n";
        }
}
$xml_output .= "</node>";

//restaurant
$xml_output .= "<node label='» Restaurant' value='3'>\n";
for($i = 0 ; $i < mysql_num_rows($resultID); $i++){
 $row = mysql_fetch_assoc($result);
        
        if ($row['cat'] == 'rest'){
     $xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] .  "' data='" . $row['file'] . "'></vid>\n";
        }
}
$xml_output .= "</node>";

//restaurant
$xml_output .= "<node label='» Funeral Homes' value='4'>\n";
for($j = 0 ; $j < mysql_num_rows($resultID); $j++){
  $row = mysql_fetch_assoc($result);
        
        if ($row['cat'] == 'funeral'){
     $xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] .  "' data='" . $row['file'] . "'></vid>\n";
        }
}
$xml_output .= "</node>";

//home
$xml_output .= "<node label='» Home' value='5'>\n";
for($k = 0 ; $k < mysql_num_rows($resultID); $k++){
  $row = mysql_fetch_assoc($result);
        
        if ($row['cat'] == 'home'){
     $xml_output .= "\t<vid label='" . $row['title'] . "' cat='" .
$row['cat'] .  "' data='" . $row['file'] . "'></vid>\n";
        }
}
$xml_output .= "</node>";

echo $xml_output;

?>
</code>

This should output an XML doc with lists of videos in categories by
type of commercial.
If you can give me some pointers or hints on how I can fix this I'd
appreciate it.



Reply via email to