0

I want a Mysql query to update all users 'status' filed in 'user' table. I can update one user by running following query.

Table

enter image description here

What I tried

update user set status = 1 where id = 1 and type = 'viber'

Do I need to run the above query inside a loop to update all users data?

I want a query like following

update user set status = 1 where id = 1 and type = 'viber' and id = 2 and type = 'twitter' ..

your help is much appreciated.

Dibish
  • 9,133
  • 22
  • 64
  • 106

4 Answers4

4

Just

update user set status=1; 

Updates your whole table.

Hikmat Sijapati
  • 6,869
  • 1
  • 9
  • 19
1

If you want to just update the status for all records then below query is useful for that.

update user set status=1; 
Harsh Barach
  • 947
  • 9
  • 18
0

The WHEREclause is used to extract only those records that fulfill a specified criterion. but here you don't want that .so just use this query to update all the records

update user set status=1; 
JYoThI
  • 11,977
  • 1
  • 11
  • 26
0

just use:

$update = mysqli_query("UPDATE user SET status = 1")or die(mysqli_error());

if this not works, you can select all data and then update each row by setting user id like this :

$select =  mysqli_query("SELECT * FROM user")or die(mysqli_error());
while($row = mysqli_fetch_array($select)){
    $id = $row['id'];
    mysqli_query("UPDATE user SET status=1 WHERE id='$id' ");
}
Pejman Kheyri
  • 4,044
  • 9
  • 32
  • 39