Good evening!

Perhaps this is nothing, but you can't do it!

In general, there is information in the database, in json format.

There are MARKES of cars in it, and in each brand there are 2-4 models!

I get this info through json_decode.

And through the cycle "foreach ($ massiv ['models'] as $ model):" I pull it into the table "CARS".

I add new models, but how to delete and edit models!

1) How to make unset, if id model is dynamic?

Here's how to remove from the "BMW" the first model "M3", so that the 2 remaining ones moved up and number 2 became number 1. and number 3 became 2 ?!

2) How to edit models, if id model again dynamic?

How can for example in the third model "BMW X6", change the model name, description and photo name?

Thanks in advance for helping a newbie!

enter image description here

enter image description here

  • if you have 5.7, you can dev.mysql.com/doc/refman/5.7/en/json-functions.html - Vfvtnjd
  • and how generally it is correct to store json in a DB. 1 - NF or not? Maybe if it makes sense to parse it first, if such are frequent especially ... - pavel
  • 1) Version php to 5.2; 2) json in the database must be stored - I have such a study! :-) - aiba

1 answer 1

Here is the correct answer:

You just had to specify the cycle

 foreach ($massiv['models'] as $key=>$model): 

where $key is the dynamic key I need!

  • Strange! How can the correct answer be NOT USEFUL ???! Who thought of this? And then what is the answer in the opinion of this clever USEFUL ??? - aiba