Hello! I'm having some trouble getting my syntax right. Here's my original query:
SELECT name, longitude, latitude, address, id, created, image,(((acos(sin(($latitude*pi()/180)) * sin((latitude*pi()/180)) + cos(($latitude*pi()/180)) * cos((latitude*pi()/180)) * cos((($longitude - longitude)*pi()/180))))*180/pi())*60*1.1515) as distance FROM items $search_sql HAVING distance <= $distance $sortOrder LIMIT 5
This works great, but I now need to count the total number of rows withouth the LIMIT for pagination purposes. In other words, something like this:
SELECT count(*) as item_count,(((acos(sin(($latitude*pi()/180)) * sin((latitude*pi()/180)) + cos(($latitude*pi()/180)) * cos((latitude*pi()/180)) * cos((($longitude - longitude)*pi()/180))))*180/pi())*60*1.1515) as distance FROM items $search_sql HAVING distance <= $distance $sortOrder
Unfortunately, this doesn't work because I'm not using "group by" with my count(*). Can someone help me figure this out? Thanks!
- Bret
SELECT name, longitude, latitude, address, id, created, image,(((acos(sin(($latitude*pi()/180)) * sin((latitude*pi()/180)) + cos(($latitude*pi()/180)) * cos((latitude*pi()/180)) * cos((($longitude - longitude)*pi()/180))))*180/pi())*60*1.1515) as distance FROM items $search_sql HAVING distance <= $distance $sortOrder LIMIT 5
This works great, but I now need to count the total number of rows withouth the LIMIT for pagination purposes. In other words, something like this:
SELECT count(*) as item_count,(((acos(sin(($latitude*pi()/180)) * sin((latitude*pi()/180)) + cos(($latitude*pi()/180)) * cos((latitude*pi()/180)) * cos((($longitude - longitude)*pi()/180))))*180/pi())*60*1.1515) as distance FROM items $search_sql HAVING distance <= $distance $sortOrder
Unfortunately, this doesn't work because I'm not using "group by" with my count(*). Can someone help me figure this out? Thanks!
- Bret