select problem
Posted: Thu Dec 29, 2005 3:27 am
Hi everyone and thanks in advance.
I am making a download script and I need to display all categories and sub categories in a select box so that I can move downloads put into the wrong category.
The database organises categories with id and parent id.
I am trying to create a function which will display a select box with the current category selected but showing all categories indented to make t easier to read.
This is as far as I have got please help.
Can I call a function within itself ?
Am I going about this the wrong way?
I am making a download script and I need to display all categories and sub categories in a select box so that I can move downloads put into the wrong category.
The database organises categories with id and parent id.
I am trying to create a function which will display a select box with the current category selected but showing all categories indented to make t easier to read.
This is as far as I have got please help.
Can I call a function within itself ?
Am I going about this the wrong way?
Code: Select all
function show_select($cat_id, $current_cat) {
global $db_connect;
global $database_db_connect;
mysql_select_db($database_db_connect, $db_connect);
$query_categories = "SELECT * FROM dload2_categories WHERE parent_id = '$cat_id'";
$categories = mysql_query($query_categories, $db_connect) or die(mysql_error());
$row_categories = mysql_fetch_assoc($categories);
$totalRows_categories = mysql_num_rows($categories);
if($cat_id == '0') { echo "<select name='categories' class='p'>"; }
if($totalRows_categories <> '0') {
do {
echo "<option value='".$row_categories['id']."'";
if($current_cat == $row_categories['id']) { echo "SELECTED"; }
echo "> -".$row_categories['name']."</option>";
show_select($row_categories['id'],$current_cat);
} while($row_categories = mysql_fetch_assoc($categories));
}
echo "</select>";
}