title: While loop foreach returning values that are repeated in next for loop
body: <p>What is happening in my code is I'm passing a keyword through a query. For each keyword I want to run the array get the results for that keyword and insert them into my database.</p>
  
  <p>The issue I'm running into is that instead of getting keyword inspiration and passing that through once it carries the value from that query, into the next.</p>
  
  <p>So for instance I have. values <code>returning id = 8, 9, 10, 11, 12</code>. Then the next query for insert should only return 5 more but instead for the next keyword it carries these values through. so it might be <code>8, 9, 10, 11, 12, 13, 14, 15, 16, 17</code>. </p>
  
  <p>If I up that value to <code>3</code>. It would carry this <code>8, 9, 10, 11, 12, 13, 14, 15, 16, 17</code> through and add five more entries to that. I'm not sure in my code where this is happening. </p>
  
  <p>Maybe a simpler example. I query a list of 2 keywords. Then out of those keywords I need to query 1 keyword through <code>sql2</code> then out of all those values place them into <code>sql3</code>. What's happening is that instead of dropping the first keyword, it carries the results through the second time. So if I query the keyword inspiration and inspire. It will query inspiration once, the second tiem around it will query inspiration and inspire. Instead of just querying inspire the second time around. </p>
  
  <pre><code>$sql = "
  SELECT `id` , `title`
  FROM `mf8uz_categories`
  WHERE `extension` = 'com_hwdmediashare'
  LIMIT 0 , 2";
  $getInfo = mysql_query($sql);
  //$numResults = mysql_num_rows($getInfo);
    while($keywordArray = mysql_fetch_array($getInfo))
      $keywords[] = $keywordArray;
      foreach($keywords as $keyword){ 
      $keyWord = $keyword['title'];
      $categoryId = $keyword['id'];
  //  echo $categoryId . $keyWord . "&lt;/br&gt;" . "&lt;/br&gt;";
      $sql2 = "SELECT `id`, `title`,`description`
  FROM `mf8uz_hwdms_media`
  WHERE `title` LIKE '%$keyWord%'
  OR `description` LIKE '%$keyWord%'
  LIMIT 0 , 5";
  //echo $sql2 . "&lt;br&gt;";
  echo $keyWord . "-------";
  $getResults = mysql_query($sql2);
  //echo $getResults;
  echo mysql_errno($db_server) . ": " . mysql_error($db_server) . "\n";
   while($row = mysql_fetch_array($getResults))
      $rows[] = $row;
      //echo $row . "&lt;/br&gt;" . "HERE" ;
      foreach($rows as $row)  {
      $echoDescription = $row['description'];
      $echoRow = $row['title'];
      $videoId = $row['id'];
      echo $videoId . "&lt;/br&gt;" . $echoDescription . "&lt;/br&gt;" . $echoRow . "&lt;/br&gt;";
  //  echo "category ID equals" . $categoryId . " " . "video id is:" . $videoId ." ". "title is:" . $echoRow . " " . "Keyword Is:" . $keyWord . "&lt;/br&gt;";
  
  $sql3 = "INSERT INTO `btheman_dwjo21c4`.`mf8uz_hwdms_category_map` (
  `id` ,
  `element_type` ,
  `element_id` ,
  `category_id` ,
  `ordering` ,
  `created_user_id` ,
  `created`
  )
  VALUES (
  '', '1', '$videoId', '$categoryId', '0', '666', '2013-11-27 16:39:09'
  );";
  
  //$getResults = mysql_query($sql3);
  //echo $sql3 . "  " . $echoRow . "&lt;/br&gt;";
  echo mysql_errno($db_server) . ": " . mysql_error($db_server) . "\n";
  }
  } 
  </code></pre>