In the database, the media table has the structure: id, attachment_url, title, alt Make a SELECT query * FROM media Display via while:

 $media_id = $media[id] <img src=\"$media[attachment_url]\"> alt: <input type='text' name='$media_id[alt]' value='$media[alt]'> title: <input type='text' name='$media_id[title]' value='$media[title]'> 

When forming each input field, an error occurs: Warning: Illegal string offset 'alt' and ... 'title'

This is how it works:

 alt: <input type='text' name='alt[$media_id]' value='$media[alt]'> title: <input type='text' name='title[$media_id]' value='$media[title]'> 

If the field name is input alt [$ media_id] and title [$ media_id], then the data is transmitted in two arrays 'alt' and 'title', where the value of the input field corresponds to $ media_id. But this is inconvenient, since there will be META fields, a text description for the photo and so on. It turns out that in order to write data, I need to pass each array of 'alt' and 'title' through a loop. I would like to get a few arrays with the names media_id with elements whose keys will be 'alt' and 'title'

How to do it?

    1 answer 1

    The error occurs because in your case $ media_id is a variable with a specific numeric value: $ media_id = $ media [id]. Naturally, when you continue to try to insert $ media_id [alt] or $ media_id [title] into your input, you get an error in response.

    Judging by your needs, I would suggest something like this:

     alt: <input type='text' name='media[$media_id][alt]' value='$media[alt]'> title: <input type='text' name='media[$media_id][title]' value='$media[title]'> 

    In this case, after you send the data to the server, you will have one $ media array, where the elements will have their id and you can very easily get the alt and title parameters, for example, $media[id]['alt'] and $media[id]['title'] .