Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert sql to Zend_Table
    text
    copied!<p>How can I convert this:</p> <pre><code>SELECT latitude, longitude, SQRT( POW(69.1 * (latitude - [startlat]), 2) + POW(69.1 * ([startlng] - longitude) * COS(latitude / 57.3), 2)) AS distance FROM TableName HAVING distance &lt; 25 ORDER BY distance; </code></pre> <p>to Zend_Table.</p> <p>I have two keys, lat and long in the database and I want to get the data which is close to the user,the query works provided by the first user which converted it yo Zend_Table but if I have data from people which <strong>are in the same city</strong> it doesn't return any data, I guess the query needs to be improved, to also show results for a bigger distance</p> <pre><code>$this-&gt;select()-&gt;from(array('c' =&gt; 'content'))...... </code></pre> <p>I have noe idea how to do this, can you guys help me?</p> <p>//LE</p> <pre><code>$data2-&gt;setIntegrityCheck(FALSE) -&gt;from(array('c' =&gt; 'content'), array('location', 'id', 'user_id', 'date', 'attachment', 'content','lat','long')) -&gt;columns(array( 'distance' =&gt; "SQRT(POW(69.1 * (lat - {$location['lat']}), 2) + POW(69.1 * ({$location['long']} - long) * COS(lat / 57.3), 2))" )) -&gt;having('distance &lt; ?', 25) </code></pre> <p>It looks like the query is wrong for finding users close to you, this one should do the trick</p> <pre><code>ASIN( SQRT( POWER(SIN((@orig_lat - abs( dest.lat)) * pi()/180 / 2),2) + COS(@orig_lat * pi()/180 ) * COS( abs (dest.lat) * pi()/180) * POWER(SIN((@orig_lon – dest.lon) * pi()/180 / 2), 2) )) as distance </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload