0

我有三个表:

user (id,name,password,......)

words (id,word,meaning)

userword (id, user_id,word_id,checking,old)

我在 php 中有一个查询:

$user= $_SESSION['userid'];
$result = mysql_query("SELECT *
                    FROM words
                    WHERE id
                    IN (
                            SELECT word_id
                            FROM userword
                            WHERE old =0
                            AND user_id =$user
                            LIMIT 10
                      ) 
                    ");

此查询正常工作,但在此之后我想更新我选择的单词并为它们设置 old=1 我该怎么办?

4

1 回答 1

2

我不推荐使用mysql_* 函数,因为它已被弃用。

mysql_query("UPDATE userword SET old='1' WHERE old='0' AND user_id='$user' AND word_id IN(SELECT id FROM words) LIMIT 10");

PDO 方法是:

$sql=$dbh->prepare("UPDATE userword SET old='1' WHERE old='0' AND user_id=? AND word_id IN(SELECT id FROM words) LIMIT 10");
$sql->execute(array($user));

更多关于PDO的信息:www.php.net/manual/en/book.pdo.php

于 2013-10-22T15:03:15.340 回答