enter image description here

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.

  • You can learn more about the output in conjunction. Give an example of the output. - Khetag Abramov
  • To check whether this category is parent or not, a condition is used. A bunch - meant that brand_id is displayed along with brand_name, included in one line, values ​​are taken from the line where they correspond to each other in one line, for example, it shows that this is the first number and is the parent category, that is returns false - Alexander
  • In the beginning, I need to at least derive from 1-8, I changed the 5-screens there, removed 3 in parent_id and set 0 to bring it out at least in order, and then I will think what to do with the subcategories, that is, from 13 19 - Alexander
  • It brings me to the page. Array ([4] => Array ([0] => Business and Work)) - Alexander
  • The task seems to be simple, but it is not carried out as it should, although everything seems to be correct ... - Alexander

0