How to do a double "Update" in Mysql

Asked

Viewed 165 times

1

I am developing software in PHP/HTML/MYSQL FRONT. I need to update a table but change two columns at once. Here comes my doubt in the $gravaprat1 variable, because it is not executing the second command (SEND = 1). Follows:

$selectsql = "select osi, entrada, vendedor, prateleira, now(), abs(DATEDIFF(now(), str_to_date(entrada,'%Y-%m-%d'))) as dias from itens;";
$res = mysqli_query($conn, $selectsql);

$gravaprat1 = "update itens set prateleira = 1 where abs(DATEDIFF(now(), str_to_date(entrada,'%Y-%m-%d'))) < 30 ***(NESSA PARTE ESTOU COM DUVIDA -->)***and update itens set enviar = 1";   
$prat1sql = mysqli_query($conn, $gravaprat1);

2 answers

6


Your SQL should look like this:

 update itens 
    set prateleira = 1 
       ,enviar     = 1
  where abs(DATEDIFF(now(), str_to_date(entrada,'%Y-%m-%d'))) < 30

In an UPDATE you should separate the fields by "," (comma), and inform them before the clause WHERE

  • Thanks Matheus, it worked right.

  • 1

    Oops, what a beauty then! Don’t forget to mark my answer as accepted if it really helped you, or any of the other answers!

3

Hello

$selectsql = "select osi, entrada, vendedor, prateleira, now(), abs(DATEDIFF(now(), str_to_date(entrada,'%Y-%m-%d'))) as dias from itens;";
$res = mysqli_query($conn, $selectsql);

$gravaprat1 = "update itens set prateleira = 1, enviar = 1 where abs(DATEDIFF(now(), str_to_date(entrada,'%Y-%m-%d'))) < 30";   
$prat1sql = mysqli_query($conn, $gravaprat1);
  • Thanks Jorge, I managed to solve this way.

  • I don’t understand why you were given a negative statement.

  • I didn’t understand either, you gave the correct answer...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.