以下のコードの通り、複数の id で where 検索して update することは可能でしょうか?配列を条件とする場合は where xx in (xx) でよろしいでしょうか?
ご教授よろしくお願い致します。
<?php if($_SERVER["REQUEST_METHOD"] == "GET") { $today = date("Y-m-d H:i:s"); $ids = $_REQUEST['ids']; $pdo = new PDO("mysql:host=xxx; dbname=xxx; charset=utf8", "xxx", "xxx", array( PDO::ATTR_EMULATE_PREPARES => false ) ); $sql = <<< SQL update list set date=:date where id=:id SQL; foreach($ids as $id) { $condition = array( ":date" => $today[$id], ":id" => $id, ); $statement = $pdo->prepare( $sql ); $result = $statement->execute( $condition ); } } exit(); ?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/04 07:08
2016/12/04 07:16 編集
2016/12/04 07:21
2016/12/04 07:33
2016/12/04 07:36
2016/12/04 07:42
2016/12/04 07:52
2016/12/04 08:04
2016/12/04 08:26
2016/12/04 08:37
2016/12/04 08:39
2016/12/04 08:42
2016/12/04 08:45
2016/12/04 08:50
2016/12/04 08:55
2016/12/04 09:01
2016/12/04 09:02
2016/12/04 09:05
退会済みユーザー
2016/12/04 09:05
2016/12/04 09:12
2016/12/04 09:36
2016/12/04 10:09
2016/12/04 11:05