Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to pass mulitple values to update records with a single query

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 291
    Comment on it

    Hello Readers if you want to update mulitple record by multiple id, then you have to use in clause in MySql

    Lets see the example as below:-

    $ids    = array(474,25, 99,101);
    

    Here I have an array $ids with multiple id's. Now this array will be inserted into mysql query.

    $params = implode(",", array_fill(0, count($ids), "?"));
    $sql    = "UPDATE MyTable SET LastUpdated = GETDATE() WHERE id IN ($params)";
    $stmt   = $mysqli->prepare($sql);
    
    call_user_func_array(array($stmt, 'bindparams'), $ids);
    $stmt->execute();
    $stmt->close();
    echo "Updated record IDs: " . implode("," $ids) ."\n";
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: