Hello.
People provide me with their 5 favorite colors. This is stored in array
$favorite = "red", "blue", "green", "orange", "black", for example.
I have a db with primary key id & columns Num1 Num2 Num3 Num4 Num5.
How can I use 1 UPDATE command to update all columns?
Obviously, I can do
UPDATE table SET Num1 = '.$favorite[0].', Num2 = '.favorite[1].', ...... WHERE id = 'id';
But really I have well over 5 items so I would like a loop if possible to say
$query = "UPDATE table SET ";
for ($i=1; $i<=1000; $i++) {
$query .= "Num".$i." = ' ".$favorite[$i]."' ";
if ($i < 1000) {
$query .= ",";
}
}
$query .= "WHERE id = 'id'";
I guess what I am asking is, is this possible? Thanks for the help.