title: breaking up strings with explode and foreach
body: <p>I'm Trying to get a php string to break down into individual words, search for them in a database and then add the results into another database..</p>
  
  <p>I currently have the string like this</p>
  
  <p>"SDGCC, ARISE, SDGFS"</p>
  
  <p>I want to search in the login tags table for tags LIKE these words i'm using this</p>
  
  <blockquote>
    <p>SELECT * FROM <code>logintags</code> WHERE <code>tag</code> LIKE '%string%'</p>
  </blockquote>
  
  <p>so that each tag is taken from the string i've tried using explode and foreach but it doesn't seem to be getting the desired effect.</p>
  
  <blockquote>
    <p>$string = $_POST['tags'];</p>
    
    <p>$tags = explode(',' $string);</p>
    
    <p>foreach($tags as $key) {</p>
    
    <blockquote>
      <p>$query = mysql_query("SELECT * FROM <code>dept_logintags</code> WHERE <code>tag</code> LIKE '%".$key."%'");
      $r = mysql _fetch _object($query);</p>
      
      <p>$insert = mysql_query("INSERT INTO <code>briefings_logintags</code> (<code>id</code>, <code>briefing_id</code>, <code>logintag_id</code>) VALUES (NULL, '$id', '".$r->id."')");</p>
    </blockquote>
    
    <p>}</p>
  </blockquote>
  
  <p>the effect i'm trying to create is for each tag create a reference between the tag id and the briefing id...</p>
  
  <p>However it seems only to be putting one correct entry in the database.</p>