<?php
include ("ad_header.php");
?>
<HTML><HEAD><TITLE>Категории</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1251">
</HEAD>
<BODY text=#000000 vLink=#00468c aLink=#ff6633 link=#0053a2 bgColor=#ffffff>
<form action="action_categories.php" method=post>
Добавить общую категорию товаров:<br>
Название: <input type=text name=newname> <input type=submit name=action value="add">
</form>
Категории:
<table bgcolor="#D3D3D3"><tr><th>Название</th><th>Подкатегории</th><th>Изменить</th><th>Удалить</th></tr>
<?php
$query="select * from categories";
$res=mysql_query($query);
while ($myrow=mysql_fetch_assoc($res)) {
$name_of_category=$myrow ["name"];
$name_of_category=stripslashes($name_of_category);
$id=$myrow ["first"];
$query="select * from subcategories where (parent='$id')";
$subres=mysql_query($query);
echo "<tr bgcolor=white><td><form action='action_categories.php' method=post><input type=text name='change_name' value=\"$name_of_category\"></td>";
echo "<td>";
echo "<select>";
while ($submyrow=mysql_fetch_assoc($subres)) {
$name_of_subcategory=$submyrow ["name"];
$name_of_subcategory=stripslashes($name_of_subcategory);
$subid=$submyrow ["first"];
echo "<option>$name_of_subcategory";
}
echo "</select>";
echo "</td>";
echo "<input type=hidden name=id value='$id'>";
echo "<td><input type=submit name=action value='change'></td>";
echo "<td><input type=submit name=action value='delete'></td>";
echo "</tr>";
echo "</form>\n";
}
?>
</table>

Подкатегории:
<table bgcolor="#D3D3D3"><tr><th>Название</th><th>Значение</th><th>Категория</th><th>Изменить</th><th>Удалить</th></tr>
<?php
$rows=mysql_num_rows($res);
if ($rows>0) {
mysql_data_seek($res,0);
}
while ($myrow=mysql_fetch_assoc($res)) {
$name_of_category=$myrow ["name"];
$name_of_category=stripslashes($name_of_category);
$id=$myrow ["first"];
$query="select * from subcategories where (parent='$id')";
$subres=mysql_query($query);
$rows_of_subres=mysql_num_rows($subres);
echo "<tr bgcolor=white><td><form action='action_categories.php' method=post>";
if ($rows_of_subres>0) {
echo "<select name=subcategory>";
while ($submyrow=mysql_fetch_assoc($subres)) {
$name_of_subcategory=$submyrow ["name"];
$name_of_subcategory=stripslashes($name_of_subcategory);
$subid=$submyrow ["first"];
echo "<option value='$subid'>$name_of_subcategory";
}
echo "</select>";
}
else {
echo "нет подкатегорий";
}
echo "</td>";
echo "<td><input type=text name='change_subcategory' value=\"New value\"></td>";
echo "<td>$name_of_category</td>";
echo "<td><input type=submit name=action value='change subcategory'></td>";
echo "<td><input type=submit name=action value='delete subcategory'></td>";
echo "</tr>";
echo "</form>\n";
}
?>
</table>
<form action="action_categories.php" method=post>
Добавить подкатегорию:<br>
Название: <input type=text name=newpodname> <select name='cat_of_new_sub'>
<?php
mysql_data_seek($res,0);
while ($myrow=mysql_fetch_assoc($res)) {
$name_of_category=$myrow ["name"];
$name_of_category=stripslashes($name_of_category);
$id=$myrow ["first"];
echo "<option value='$id'>$name_of_category\n";
}
?>
</select> <input type=submit name=action value="add subcategory">
</form>
</BODY></HTML>
<?php
mysql_close ($link);
?>