title: Select Value Closest to a Variable
body: <p>I am trying to run a function that queries a database table for the numeric value <code>mba_score</code> closest to a variable <code>$runscore</code>.  My function looks this way:</p>
  
  <pre><code>public function get_player($runscore)
  {
     $per = $this
               -&gt;db
           -&gt;select('mba_id, abs($runscore - mba_score) as mba_rate', FALSE)
           -&gt;order_by('mba_rate', 'ASC')
           -&gt;get('nba_scores');
           -&gt;limit(1);
  
          if ($per-&gt;num_rows &gt; 0) {
              $p = $per-&gt;row_array();
              return $p['nba_id'];
          }
          return false;           
          }
  </code></pre>
  
  <p>The error I get is : </p>
  
  <pre><code>"Error Number: 1054
  
  Unknown column '$runscore' in 'field list'"
  </code></pre>
  
  <p>I've tried writing and re-writing this segment a number of times and haven't been able to get a result.</p>