Answer the question
In order to leave comments, you need to log in
How to merge values from $_POST to remove unnecessary and write everything to the database?
Initially they come like this
[5] => Array(
[post_id] => 1038
[data_type] => photoSignImage
[post_data] => image.jpg
)
[6] => Array(
[post_id] => 1038
[data_type] => photoSignText
[post_data] => some text
)
[5] => Array(
[post_id] => 1038
[data_type] => photo
[post_data] => image.jpg|||some text
)
Answer the question
In order to leave comments, you need to log in
If I understand correctly, then at the input in one element, a picture, in the second a comment to it. In this case, everything can be stored in two tables, the first is the main entity id of which appears in the post_id key. The second is a table of photos with the address of the photo in one field and a comment to it in the second. More or less like this:
foreach ($data as $item)
{
$insert = array();
if ($item['data_type'] === 'photoSignImage')
{
$insert['path'] = $item['post_data'];
}
elseif ($item['data_type'] === 'photo')
{
$insert['comment'] = $item['post_data'];
}
$insert['id'] = $item['post_id'];
db::insert_record('table', $insert);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question