[QUOTE
$Query = "SELECT * FROM categories WHERE `id`=$id";
$res = mysql_query($Query);
if(mysql_num_rows($res)==0){
echo "You have to delete all companies first in this category to be able to delete the category!";
}else{
$Query = "DELETE FROM categories WHERE `id`=$id";
$Result = mysql_query($Query) or die("Error: ".mysql_error()." in query: ".$Query);
echo "The category is now deleted";
}
[/B][/QUOTE]
It doesnt work because you have it the wrong way round. The line
if(mysql_num_rows($res)==0) is saying if there are 0 records in the database. In your code you are saying if there are 0 records bring up the echo else delete everything. You can change it either so that the if statement reads
if(mysql_num_rows($res)>0){
or swap the resulting code between the if and the else