title: Separate mysql_query from foreach validation check php
body: <p>This is a snippet of my code. I essentially I have a new array I want to insert into tablename, but before I do that I validate the new stat figures against the old ones, confirm they are numeric and insert into a new row.</p>
  
  <p>I realise what I have done, the mysql_query is inside the foreach loop, it inserts 5 rows all the same. I want it to only insert 1 new row.</p>
  
  <p>How Do I take the mysql_query outside the loop yet keep the validation that the foreach loop provides before attempting to insert a new row?</p>
  
  <pre><code>foreach ($statnumber as $element) {
  if ($statnumber != $LastWeeksStats &amp;&amp; is_numeric($element)) {
      mysql_query("INSERT INTO tablename (idproducts, stat1, stat2, stat3, stat4, stat5, superstat1) VALUES('8', '$statnumber[0]', '$statnumber[1]', '$statnumber[2]', '$statnumber[3]', '$statnumber[4]', '$statnumber[5]')") or die(mysql_error());  
      } else {
      echo "'{$element}' is NOT numeric or results same as last week", PHP_EOL;
  }} 
  mysql_close();
  </code></pre>