I have an array with different IDs which I get from my database.
$fotos_temp_list=explode(",",$fotos_temp["fa_id"][0]);
Result: fa_id => 15,16,17,18
Now I want to update all rows inside another table with the IDs 15,16,17,18 and insert a specific '$id' into a column called 'fa_ev_id'.
In this example I set:
$id=1;
Now my foreach-loop looks like this:
foreach ($fotos_temp_list as $key) {
UPDATE images SET fa_ev_id = Concat(fa_ev_id , ',' ,'".$id."') where fa_id='".$key."' ";
}
This part is working too. Every row with my IDs (in my example: 15,16,17,18) gets updated.
Problem:
When I run the foreach-loop again, the '$id' will be saved again inside the row. See here:
Question:
How is it possible, that I can check if '$id' is already inside the row and if so, it gets skipped? Here is what I tried to do:
foreach ($fotos_temp_list as $key) {
if (!in_array($id,$key)===true) {
UPDATE fotoalbum SET fa_ev_id = Concat(fa_ev_id , ',' ,'".$id."') where fa_id='".$key."'
}
}
I think the in_array function checks if '$id' id already inside '$key' and if it is true, the UPDATE statement is done. Therefore I added '!in_array' but it doesn´t seems to work. Does anyone has an idea what I am doing wrong? I just want to check if the '$id' is already inside my database row and if so, it should not insert the '$id' again.
I appreciate any advice.

$fotos_temp_listat the time you run this? And why on earth are you storing multiple values inside a single field? A properly designed relational database would not do this. You should have one value per field. If you don't, it indicates a flaw in your schema design. Have you studied relational database design and normalisation at all?mysqliand PDO where any user-supplied data is specified with a?or:nameindicator that’s later populated usingbind_paramorexecutedepending on which one you’re using.