Good day, gentlemen. there is the following foreach ($result_list as $entry2) { $row[$entry2["id"]][] = $entry2["value_obj"]; } foreach ($result_list as $entry2) { $row[$entry2["id"]][] = $entry2["value_obj"]; }

he leads so

 Array ( [324] => Array ( [0] => 7 [1] => 16 [2] => 21 [3] => 26 [4] => 44 [5] => 33 [6] => 88 [7] => 1 [8] => 1 ) [307] => Array ( [0] => 5 [1] => 48 [2] => 67 [3] => 88 [4] => 5 [5] => 2 [6] => 52 [7] => 55 [8] => 56 [9] => 58 ) 

Where 324 and 307 product ID and all that in the array of its characteristics. The question of how to make it so that instead of indices the names of the characteristics are displayed which I take from the database "param_name"

 $result=mysql_query($sql ); $result_list = array(); while($row = mysql_fetch_array($result)) { $result_list[] = $row; } 

Here's the query, but the fact is that when I do $row[$entry2["id"]][]=$entry2["param_name"]. $entry2["value_obj"]; $row[$entry2["id"]][]=$entry2["param_name"]. $entry2["value_obj"]; he only lists me all separated by a comma.

 $sql="SELECT ore_apartment_city.name_ru,address_ru,description_ru,lat,lng,ore_apartment.id,phone,ore_apartment_obj_type.name_ru,ore_apartment_kind.representation,price,ore_apartment_properties.property_id,ore_apartment_properties.value_obj,ore_additional_properties.name,ore_additional_properties.param_name FROM ore_apartment,ore_apartment_city,ore_apartment_obj_type,ore_apartment_kind,ore_apartment_properties,ore_additional_properties WHERE ore_apartment_city.id=ore_apartment.city_id AND ore_apartment_obj_type.id=ore_apartment.obj_type_id AND ore_apartment_kind.id=ore_apartment.kind_id AND ore_apartment.id = ore_apartment_properties.apartment_id AND ore_additional_properties.id = ore_apartment_properties.property_id"; 
  • Code is needed that explains what $ result_list is - Uranus
  • Pardonte `$ result = mysql_query ($ sql); $ result_list = array (); while ($ row = mysql_fetch_array ($ result)) {$ result_list [] = $ row; } ` - Gregory Mikhailov
  • PHP displays what you got from the MySQL server. And the information received hints that the information you need in this data is stupid. Which means one thing - you did not ask from the server. So do not try to extract from the data set given to you what is not in it and ask. otherwise. That is, to change the query to the MySQL server. But I somehow do not see the text of the request in your question. - Akina
  • @Akina Added to post, for there was an excess of characters - Grigory Mikhailov
  • Something the query text slightly corresponds to the result obtained ... in the query, 14 fields are selected, and as a result of its execution with fields it is not enough. Well, it would be nice to tell where the much-needed names of the characteristics lie, and what is this DATABASE "param_name". Ps. set all the tables in the query text aliases - the text is greatly reduced. And specify aliases of tables for ALL fields, this will remove ambiguity. - Akina

2 answers 2

if I correctly understood what you want, then something like this:

 foreach ($result_list as $entry2) { $row[$entry2["id"]] = [$entry2["param_name"] => $entry2["value_obj"]]; } 
  • I'll check it out to the point - Grigory Mikhailov
  • Parse error: syntax error, unexpected '[' in - Gregory Mikhailov
  • well, you have a puff old - does not support a short array write - [] - myxaxa
  • $ row [$ entry2 ["id"]] = array ($ entry2 ["param_name"] => $ entry2 ["value_obj"]); - this is how it should work ^ _ ^ - myxaxa

Made

 foreach ($result_list as $entry2) { $row[$entry2["id"]][$entry2["param_name"]]=$entry2["value_obj"]; } 

And to dear @Akina, I wish to keep my mind over and above myself and not to give "very necessary" advice and take the person away from the topic who is not well versed in it