I am having trouble getting category tree stuctures from a database into <select> box (drop down menu).
with out the <select> code, everything works perfect, but when i try to load it into a <select> box nothing really shows up... but if i look at the "view source" i see this...
<td width="29%"><font size="2" face="Tahoma">Select Category</font></td>
<td width="32%"><SELECT name="categories">
Error 0 :
here is my php code...
<SELECT name="categories">
<?php
// category functions that process category trees
function categories ($id, $depth) {
if ($id == 'NULL')
$query = "SELECT * FROM categories WHERE Parent IS NULL";
else
$query = "SELECT * FROM categories WHERE Parent = '" . $id . "'";
$result = mysql_query($query);
if (mysql_num_rows($result) < 1)
return;
while($row = mysql_fetch_array($result)) {
categories2 ($row, $depth);
}
}
// function that puts everthing into a <select> or just prints it
function categories2 ($row, $depth) {
if (($result = @ mysql_query ($query, $connection))){
while ($category = mysql_fetch_array($result)){
?>
<option name="<?php echo $category['ID']; ?>">
<?php
echo($depth . $row['Name']); ?></option><?php
$depth = $depth . $row['Name'] . " > ";
categories ($row['ID'], $depth);
// contiue if statement
}
}
else
die("Error " . mysql_errno() . " : " . mysql_error());
}
// db data
$hostName = 'localhost';
$username = 'usrname';
$password = 'pw';
$databaseName = 'dbname';
//connect to DB
if (!isset($connection))
{
if (!($connection = @ mysql_connect($hostName, $username, $password)))
showerror();
if (!mysql_select_db($databaseName, $connection))
showerror();
$open = true;
}
// Run the Functions
categories("NULL", "");
?>
</select>
does anyone know why this isn't working??
I would really appreciate your help