title: Grabbing users with no orders with mysql & php, simplifying this
body: <p>Currently, this is my php script:</p>
  
  <pre><code>            $users = DB::select('id', 'email', 'firstname', 'lastname')-&gt;from('users')-&gt;execute()-&gt;as_array();
  
              $orders = array();
              foreach($users as $user)
              {
                  $anyOrder = DB::select('id')-&gt;from('orders')
                  -&gt;where('orders.date_created', 'BETWEEN', array($from, $to))
                  -&gt;and_where('orders.user_id', '=', $user['id'])
                  -&gt;and_where_open()
                  -&gt;and_where('orders.status', '=', 'new')-&gt;or_where('orders.status', '=', 'delivered')
                  -&gt;and_where_close()
                  -&gt;execute()-&gt;count();
  
                  if($anyOrder == 0)
                  {
                      $orders[] = array('firstname' =&gt; $user['firstname'], 'lastname' =&gt; $user['lastname'], 'email' =&gt; $user['email']);
                  }
              }
  </code></pre>
  
  <p>(DB::select() is a query, im using kohana query builder).</p>
  
  <p>This works fine, until now when I have over thousands users.</p>
  
  <p>How can this be simplified and quicker?</p>
  
  <p>What the script does is saving all who does not have an order between $from and $to into the $orders array.</p>