I've got the following array $weight and I want to store these values to the weight column in mysql table.
Array
(
[0] => 12
[1] => 14
[2] => 16
[3] => 9
[4] => 7
)
The database table structure is,
+----------------------------+--------+------+
| Indicators | Weight | Rank |
+----------------------------+--------+------+
| Elevation | 0 | 0 |
| Distance from the sea | 0 | 0 |
| Natural Coastal Protection | 0 | 0 |
| Water Bodies | 0 | 0 |
| Precipitation | 0 | 0 |
+----------------------------+--------+------+
I'm expecting the result as,
+----------------------------+--------+------+
| Indicators | Weight | Rank |
+----------------------------+--------+------+
| Elevation | 12 | 0 |
| Distance from the sea | 14 | 0 |
| Natural Coastal Protection | 16 | 0 |
| Water Bodies | 9 | 0 |
| Precipitation | 7 | 0 |
+----------------------------+--------+------+
Tried the following query, but it doesn't seem to insert.
foreach($weight as $value)
{
$insert_weight="UPDATE geographic_main
SET Weight='$value'
WHERE Indicators=('Elevation','Distance from the sea',
'Natural Coastal Protection','Water Bodies', 'Precipitation') ";
I'm not sure if I'm right in the WHERE part. Please suggest. }