title: MySQL find closest integer between two columns
body: <p>Right now, I have an IP which I am converting to an integer and then trying to find the closest match to a location from a table.</p>
  
  <p><img src="https://i.stack.imgur.com/gm5Np.png" alt="enter image description here"></p>
  
  <p>I'm doing this right now:</p>
  
  <pre><code>$sql = "SELECT * FROM table WHERE IP_FROM &gt;= $x AND IP_TO &lt;= $x LIMIT 1;";
  </code></pre>
  
  <p>and sometimes I get no result as $x falls through the cracks.  </p>
  
  <p>I'd like to know of a way where I can get the closest row.</p>
  
  <p>Thanks</p>