...it kinda makes sense. If you just want the option of deleting to be enabled or disabled, why don't you change run a query to check to see if it has a parent before you delete? Otherwise, if you run a query to get all the information anyway, do something like this:
<?php
$query = "SELECT * FROM categories";
$result = mysql_query($query, $conn) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
\\echo id and title
if ($row['parent'] != 0) {
echo "Cannot delete";
} else {
echo "Can delete";
}
}
?>
This assumes that if the parent field is 0, the category doesn't have any parents.
I have a feeling that's not what you meant though. If what you really want is to have the option to delete only if the category is not a parent of any other categories (or, it doesn't have any children), then you probably want this for:
<?php
$query = "SELECT c1.*, count(c1.parent) as parent_count FROM categories c1
LEFT JOIN categories c2 ON c1.id = c2.parent
GROUP BY c1.id";
$result = mysql_query($query, $conn) or die(mysql_error());
while ($row = mysql_fetch_assoc($result)) {
\\echo id and title
if ($row['parent_count'] != 0) {
echo "Cannot delete";
} else {
echo "Can delete";
}
}
?>
I haven't tested that, so I'm not completely sure it will work, but I'm sure if you play around with that query and check what results you get, you'll be able to get it working.