I have this array:
Array ( [3] => 40000 [5] => 20300 [17] => 29000
[4] => 35000 [6] => 59000 [54] => [34] => [7] => 113000
[55] => [35] => [8] => 219000 [56] => [36] => [9] => 40600 )
array keys = id
array values = price
I want update table with this values and when the price is exist, save the price and when the price is not exist, save the "NULL"
Here my code:
<form method="post">
<?php
$qr2=$mysqli->query("SELECT `price`,`id` FROM `pricing`");
while($row2=$qr2->fetch_object()){
?>
<input type="text" class="nw-prc" value="<?php echo $row2->price; ?>" name="price[<?php echo $row2->id; ?>]">
<?php
}
?>
</form>
<input type="submit" id="up" name="up" value="save">
<?php
if (isset($_POST['up'])) {
$price=$_POST['price'];
}
$keys=array_keys($price);
$values=array_values($price);
foreach($keys as $k){
foreach($values as $v){
$mysqli->query("UPDATE `pricing` SET `price`='$v' WHERE `id`='$k'");
}
}
?>
print_r($_POST)to see what is the result we get?