title: Combine a variable with SELECT results into an INSERT statement
body: <p>I have 3 tables:</p>
  <blockquote>
  <p>Users - uID (INT AUTO_INCREMENT), name (VARCHAR)</p>
  <p>Movies - mID (IN AUTO_INCREMENT), title (VARCHAR)</p>
  <p>Watched - uID (INT), mID (INT)</p>
  </blockquote>
  <p>I'm writing a php function that constructs a query which adds records of movies watched by a particular person. Here's what I've come up with so far:</p>
  <pre><code>function set_watched($name, $movies){
      $sql = &quot;SET @userid = (SELECT uID FROM users WHERE name = '$name' LIMIT 1); &quot;;
      $sql .= &quot;INSERT INTO watched (uID, mID) VALUES ('&quot;;
  
      foreach ($movies as $index =&gt; $movie){
  
      }
  
  }
  </code></pre>
  <p><strong>My question:</strong>
  Is there a way to combine the @userid variable with the results of a <code>SELECT mID FROM MOVIES WHERE title = $movie OR title = $movie [generated with foreach]</code>?</p>
  <p>I don't want to generate separate SELECT statements for every movie title. Perhaps I don't even have to use the @userid variable at all?</p>