0

I have three table:

user (id,name,password,......) words (id,word,meaning) userword (id, user_id,word_id,checking,old) 

and i have a query in 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 ) "); 

this query works properly but after this I want to update words that I selected and set old=1 for them what can I do?

2
  • 2
    run an update query? Commented Oct 22, 2013 at 15:03
  • 1
    Er, see JOIN... and why are you limiting the result to 10 rows (and 10 'random' rows at that)!?!? Commented Oct 22, 2013 at 15:26

1 Answer 1

2

I don't recommend using mysql_* functions because it's depreceated.

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

A PDO approach would be :

$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)); 

More About PDO : www.php.net/manual/en/book.pdo.php

Sign up to request clarification or add additional context in comments.

1 Comment

I have a lot of words in userword that old=0 and user_id= $user for them but I want to update some of them that I selected them before

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.