Welcome Guest, Not a member yet? Register   Sign In
Paginate problem with aggregate column
#1

Hello,
Sorry for my english i'm french guy.

I would like to use an aggregated column (distance with cos and tan) to filter on the distance between two users with a having count, problem: I still get this error, can you help me?

mysqli_sql_exception # 1054
Unknown column 'distance' in 'where clause'

My select request is : $this->select('( 6371 * acos( cos( radians('.$this->escapeString($array['lat']).') ) * cos( radians( user_lat ) ) * cos( radians( user_lon ) - radians('.$this->escapeString($array['lon']).') ) + sin( radians('.$this->escapeString($array['lat']).') ) * sin(radians(user_lat)) ) ) as distance');

thank you for your help
Reply
#2

@Wiloooo ,

Have you tried your SQL statement directly in MySQL? Also, can we see the code where the SQL statement is set up and submitted for execution? This will help us determine if your code and SQL statement is correctly set up/configured.
Reply
#3

(This post was last modified: 12-03-2021, 11:44 AM by Wiloooo.)

(11-30-2021, 08:37 AM)php_rocs Wrote: @Wiloooo ,

Have you tried your SQL statement directly in MySQL?  Also, can we see the code where the SQL statement is set up and submitted for execution?  This will help us determine if your code and SQL statement is correctly set up/configured.

Thank you for your answers,
yes my SQL request is good on my phpmyadmin

The problem comes from the autogenerated count for the pagination with "select *", my distance column is not in the table because it is an aggregated column

==> $this->select('( 6371 * acos( cos( radians('.$this->escapeString($array['lat']).') ) * cos( radians( user_lat ) ) * cos( radians( user_lon ) - radians('.$this->escapeString($array['lon']).') ) + sin( radians('.$this->escapeString($array['lat']).') ) * sin(radians(user_lat)) ) ) as distance');

I hope you understood me
Reply
#4

@Wiloooo ,

Question...are you trying to get one value from your select statement? If that is the case, why even use Mysql. You could accomplish the same thing with PHP math.
Reply
#5

(11-30-2021, 05:25 AM)Wiloooo Wrote: mysqli_sql_exception # 1054
Unknown column 'distance' in 'where clause'

My select request is :  $this->select('( 6371 * acos( cos( radians('.$this->escapeString($array['lat']).') ) * cos( radians( user_lat ) ) * cos( radians( user_lon ) - radians('.$this->escapeString($array['lon']).') ) + sin( radians('.$this->escapeString($array['lat']).') ) * sin(radians(user_lat)) ) )  as distance');

What the whole query that CI4 sends to MySQL?
Reply
#6

(This post was last modified: 12-07-2021, 11:27 AM by Wiloooo.)

(12-03-2021, 12:58 PM)php_rocs Wrote: @Wiloooo ,

Question...are you trying to get one value from your select statement?  If that is the case, why even use Mysql.  You could accomplish the same thing with PHP math.

False, if I want to sort by distance with a given distance, php math is useless

(12-04-2021, 07:41 PM)kenjis Wrote:
(11-30-2021, 05:25 AM)Wiloooo Wrote: mysqli_sql_exception # 1054
Unknown column 'distance' in 'where clause'

My select request is :  $this->select('( 6371 * acos( cos( radians('.$this->escapeString($array['lat']).') ) * cos( radians( user_lat ) ) * cos( radians( user_lon ) - radians('.$this->escapeString($array['lon']).') ) + sin( radians('.$this->escapeString($array['lat']).') ) * sin(radians(user_lat)) ) )  as distance');

What the whole query that CI4 sends to MySQL?

sorry i didnt understand Undecided
Reply
#7

Try:
PHP Code:
$this->select('( 6371 * acos( cos( radians('.$this->escapeString($array['lat']).') ) * cos( radians( user_lat ) ) * cos( radians( user_lon ) - radians('.$this->escapeString($array['lon']).') ) + sin( radians('.$this->escapeString($array['lat']).') ) * sin(radians(user_lat)) ) ) as distance'false); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB