M
M
musclecode2019-07-02 22:12:55
MySQL
musclecode, 2019-07-02 22:12:55

How to correctly compose a database to get an array of the following type (more on that later)?

you need to get into the php code, after the request, an array of this kind,
for example

[
    'animal' => 'cat',
    'body' => ['head' => 1, 'paw' => 4],
    'ability' => ['run' => 10, 'jump' => 2]
]

on json does quite easily, through mysql how tables interact I can’t figure out how to design a table correctly, how many tables do I need to create at all?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Immortal_pony, 2019-07-02
@Immortal_pony

Offhand two options.
Option #1, use if the 'body' and 'ability' sets are the same for all animals animal
table, fields: id (int), title (varchar)
animal_body table, fields: id (int), animal_id (int), head (int), paw (int)
animal_ability table, fields: id (int), animal_id (int), run (int), jump (int)
Option #2, use if 'body' and 'ability' sets are different for all animals
table animal, fields: id (int), title (varchar), body (json), ability (json)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question