php – Show delete link only if there are no child categories

Question:

I have a database with the following columns:

|id|id_pai|nome_categoria|
+--+------+--------------+
|01|   0  | Eletronicos  |
|--+------+--------------+
|02|   01 | Notebook     |
|--+------+--------------+
|03|   0  | Livros       |
+--+------+--------------+
|04|  03  | Romance      |
+--+------+--------------+

I want to return a table in html with name only of the parent category and a link to delete, but the link can only appear if the category has no child category.

Answer:

I think it would be something like:

SELECT id, nome_categoria
FROM categoria
WHERE id NOT IN
    (SELECT DISTINCT id_pai
     FROM categoria);
Scroll to Top
AllEscort