Answer the question
In order to leave comments, you need to log in
How to display data from stored procedures in MySQL in PHP?
I have the following table in the database that describes categories with an infinite number of parents.
id, name, parent (where parent is the id of the parent category)
there is also a stored procedure that lists all categories as long as parent!=0, that is, as long as the category has no parent. The procedure has an input parameter - this is the id of the last element. (from it you need to bring the tree to the very top)
CREATE PROCEDURE `breadcrumbs`(IN cat INT)
BEGIN
DECLARE i INT DEFAULT 0;
WHILE cat!=0 DO
SELECT * FROM category WHERE category.id=cat;
SET cat=(SELECT category.parent FROM category WHERE category.id=cat);
END WHILE;
END;
Answer the question
In order to leave comments, you need to log in
Everything turned out to be trite ... There was a small error in the code above. And you can display the result of a MySQL stored procedure in PHP using a multi-query.
here is man: see 3 example
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question