0

I have this php file to deal with my sql, I want to make many statement on one record in the database for examole I have this query :

$query = mysql_query("SELECT bloodGroup,quantity,bank_id FROM medical_bank_notification WHERE seen=1");

I want to make all the records which were selected in the $query to have the field seen=0 after it has been selected, so I thought that I have to know all the IDs from the first query and then write another query:

$sql2 = "INSERT INTO medical_bank_notification (seen) VALUES (0) WHERE ID=_????_";
niha
  • 37
  • 5
  • 2
    Please, [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and consider using PDO, [it's not as hard as you think](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Jun 01 '15 at 21:15
  • http://php.net/mysql_fetch_assoc, get your ids, use those to run the other insert. – Marc B Jun 01 '15 at 21:16
  • 2
    cant you just run `UPDATE medical_bank_notification set seen=0 WHERE seen=1` after the select of course ;-) –  Jun 01 '15 at 21:17
  • I don't get why you would do an `INSERT` instead of an `UPDATE` unless you want to have duplicate rows for some reason. Either way `INSERT`s can't have a `WHERE` unless it's a sub-query. See: http://dev.mysql.com/doc/refman/5.6/en/insert.html – Mike Jun 01 '15 at 21:22
  • please can u tell me how to write the update statement? – niha Jun 01 '15 at 21:26

1 Answers1

-1

use mysqli_multi_query($con,$query)

$query = "INSERT INTO table1 (column1,column2,column3)
VALUES (value1,value2,value3);";

$query .= "INSERT INTO table2 (column1,column2,column3)
VALUES (value1,value2,value3);";

//excute query

if(mysqli_multi_query($con,$query))
                {
                 while (mysqli_next_result($con) && mysqli_more_results($con)) 
                    {
                       if ($resSet = mysqli_store_result($con)) { mysqli_free_result($resSet); }

                    if (mysqli_more_results($con)){ }
                    }
                        echo 'success';
                }