Right heres my working solution:
$sql = "SELECT `sub_category` FROM `category`, `sub_category` WHERE category.category_id = sub_category.category_id AND `category` = '$deleteCategoryName'";
$result1 = mysql_query($sql);
$test = mysql_fetch_row($result1);
if ($test != "") {
$deleteCategory_sql = "DELETE `category`, `sub_category` FROM `category`, `sub_category` WHERE category.category_id = sub_category.category_id AND `category` = '$deleteCategoryName'";
$deleteCategory_result = mysql_query($deleteCategory_sql) or die("error function deleteCategory, deleteCategory_sql");
}
else {
$sql2 = "DELETE FROM `category` WHERE `category` = '$deleteCategoryName'";
$reuslt2 = mysql_query($sql2);
}
I expect why your asking why this is better?
Well its better because its only 2 mysql queries per delete, insteed of the 3 queries surgested above. While there is more php this does not take up much more cpu resources. If my database is on another server and not local and I have 10,000 people all deleting a category the bandwidth between php server and database is high, so the difference bettween 2 and 3 mysql queries can make a big difference to bandwidth costs. Also it puts the mysql server under less stress. Note this code is mysql 4 only as it deletes from more than one tables, not mysql 3 compatable (I think).