简体   繁体   中英

How to set variable in sql query

I am trying to set a variable for later use in SQL. My SQL query is as follows:

$sql ="SELECT *,$filterqueryage (
(
(
ACOS( SIN( (".$lat." * PI( ) /180 ) ) * SIN( (
 `latitude` * PI( ) /180 ) ) + COS( ( ".$lat." * PI( ) /180 ) ) * COS( (
 `latitude` * PI( ) /180 )
) * COS( (
( ".$lng." -  `longitude` ) * PI( ) /180 )
)
)
) *180 / PI( )
) *60 * 1.1515 * 1.609344
) AS distance
FROM users AS u
LEFT JOIN usermeta AS um1 ON u.id = um1.user_id
$filterquery

WHERE um1.meta_key = 'subjects'
AND um1.meta_value REGEXP '$subjectsvalues'
$filterqueryup 

GROUP BY u.ID
HAVING distance < $km $filterqueryupage ORDER BY distance ASC";
$users = DB::select($sql);

I would like to store the distance variable for use in the result display, the variable is used "AS distance" in the SQL query. How can i set the variable so i can call it in php, eg. $distance = $user->distance?

'".$var."'

尝试这种方式对我有用

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM