title: Compare and remove rows based on values [MYSQLi]
body: <p>So this is what I'm trying to do and have no idea how to proceed with.</p>
  
  <p>There are two tables. <code>db1</code> and <code>db2</code>. Db1 contains two <code>column</code>s, <code>id</code> and <code>PriceMin</code>.</p>
  
  <hr>
  
  <p><code>Db2</code> contains columns <code>id</code> and <code>Price</code>.</p>
  
  <hr>
  
  <p><code>Db1</code> is the mother database in which each <code>id</code> contains a set price. This <code>db</code> is static. </p>
  
  <hr>
  
  <p><code>Db2</code> is the child database in which people <strong>vote</strong> for each item ( read: <code>id</code> ) and a script uses the <code>avg()</code>  function after matching id's and prices to show data.</p>
  
  <hr>
  
  <p>Now, since this is a script which asks for votes, it has a huge flaw: it can be manipulated. So I'm trying to have a script run every couple of hours which goes through <code>db2</code>, matches the <code>id</code> and deletes each row (vote) from <code>db2</code> which has a id and it's price is over 200% of the same <code>id</code> in <code>db1</code>.</p>
  
  <hr>
  
  <p>My solutions up to now:</p>
  
  <ol>
  <li><p>Have each db be queried and fetched into an array and use <code>str_replace</code> via using an <code>if</code> function. This does not seem logical nor doable.</p></li>
  <li><p>Use a script before <code>POST</code> to check which will double the queries to the DB, and is not logical. It will also be a stupid idea since every vote will require a query. </p></li>
  </ol>
  
  <hr>
  
  <p>All out of ideas and would really appreciate a guide or advice in which way to go through.</p>
  
  <p>Thanks in advance !</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>Came up with something but it doesn't work:</p>
  
  <pre><code>&lt;?php
  include ('go.php');
  $sql = "delete 
  from db2
  where db2.id IN (select db1.id where db2.price &gt; db1.price * 2)" or die(mysqli_error($sql));
  ?&gt;
  </code></pre>