title: How to share value based on availability in database
body: <p>I've been thinking if this is possible. Is there a way I can get the value of an input field from a form, and split or share this value among some receivers stored in my database?</p>
  
  <p>Let's say the user entered $10, and I want to share this amount to some users stored in the database who want to receive $7 and $3 respectively.</p>
  
  <p>The issue for me now is that these values are not static, they change. I cannot really determine the amount that a user will enter in the form, and the amount that the stored users want to receive too varies. </p>
  
  <p>How do I come up with an algorithm such that:</p>
  
  <ul>
  <li>it checks the amount the user entered,</li>
  <li>keeps sharing it among the receivers, until no receiver again OR amount is exhausted?</li>
  </ul>
  
  <p>This is the code I've written so far... I'll just add what's necessary here:</p>
  
  <pre><code>//function to get users from database
  function getUsers() {
      $users = DB::getInstance()-&gt;query("SELECT * FROM `table` WHERE `status` = 'receiver'");
      if ( $users-&gt;count() ) {
          return $users-&gt;results();
      } else {
          return false;
      }
  }
  
  //then the process
  $enteredAmount = Input::get('amount'); //from the form
  if ( getUsers() ) {
      $users = getUsers();
  //this is where I am stuck. don't know what to do from here
  }
  </code></pre>
  
  <p>Can someone please point me to the right direction?</p>