Good day to all. There was a problem, it is necessary to display an array on the page, namely the value of brand_id, brand_name and parent_id, so that the elements of the line are in a bundle, real estate in the first place, transport in the second (in order to the end of the list), and also parents have descendants with existing parent_id. Found a solution to this issue, but there are some problems that have arisen along the way.
function catalog(){ $query = "SELECT * FROM brands ORDER BY parent_id, brand_name" ; $res = mysql_query($query) or die(mysql_query()); //массив категорий $cat = array(); while($row = mysql_fetch_assoc($res)){ if(!$row['parent_id']){ $cat[$row['brand_id']][] = $row['brand_name']; }else{ $cat[$row['parent_id']]['sub'][$row['brand_id']] = $row['brand_name']; } return $cat; } } All this is necessary in order to create a menu of categories in one of the bars. The problem is that everything is executed, only instead of executing all the lines, only one is executed. I later realized that this is all due to the fact that the order of the lines with the original values does not allow to display everything in order, it is necessary that the names be alphabetically and parents in order. Now I think what to do or create new names so that sorting or sorting is not needed so that the program runs.
