Mysql
 sql >> Database >  >> RDS >> Mysql

se Riga1 =Valore 1, Aggiorna altre righe

Non hai menzionato il campo del numero di telefono, quindi ho pensato che fosse phone_number :

$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password', array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));

if (isset($_REQUEST['data'])){
    $data = json_decode($_REQUEST['data']);
    if($data->phonenumber){
        $stmt = $db->prepare("SELECT `id` FROM `test` where `id`=:phone_number");
        $stmt->execute(array(':phone_number' => $data->phonenumber));
        $row_count = $stmt->rowCount();

        if($row_count && ($data->phonenumber != '')){
            $stmt = $db->prepare("UPDATE `test` SET `longitude`=:longitude, `latitude`=:latitude, `timestamp`=:timestamp WHERE `id`=:phone_number");
            $stmt->execute(array(':longitude' => $data->longitude,':latitude' => $data->latitude,':timestamp' => $data->timestamp,':phone_number' => $data->phonenumber));
        }
    }
}