Jump to content

Recommended Posts

Using MySQL 4.1.22-standard

 

 

The following code works when $fuzzy >= 0.125

 

But when $fuzzy <= .05, the first seems to be working as expected, but the second query returns no results.  Anyone know why, or how to make it work with smaller values for $fuzzy?

 

 

Query 1

$sql = "SELECT AVG( user_lat ) AS AVG_Lat, AVG( user_long ) AS AVG_Lon, count( * ) AS Number_Users, `user_id`, ROUND( user_lat / $fuzzy ) * $fuzzy AS fuzzy_lat, ROUND( user_long / $fuzzy ) * $fuzzy AS fuzzy_lon
FROM `phpbb_users` 
WHERE user_lat != ''
GROUP BY fuzzy_lat, fuzzy_lon
ORDER BY Number_Users DESC";

for each row returned I then run a second query using the fields fuzzy_lat and fuzzy_lon which were returned from the previous query.

	$sql = "SELECT `user_id`, `username`
		FROM `phpbb_users` 
		WHERE ROUND( user_lat / $fuzzy ) * $fuzzy =  $fuzzy_lat
		AND  ROUND( user_long / $fuzzy ) * $fuzzy = $fuzzy_lon;

Link to comment
https://forums.phpfreaks.com/topic/69775-query-returns-no-results-when-it-should/
Share on other sites

It could be a result of using floating point numbers where an expected result of, say, 0.5 is actually stored as 0.500000001.

 

Equality with FP numbers is an inexact science. Instead of

 

where fp1 = fp2

 

try

 

where abs(fp1 - fp2) < 0.0001

 

to see if they are sufficiently close to be considered equal.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.