Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

how to use between condition

I got latitude value and longitude value in client ip address how to use between condition in phalcon.....i try to between condition in this coding

$conditions = array();
$conditions[] = 'status = '.$status;
$conditions[] = 'is_featured = '.$featured;
 $conditions['lat_value BETWEEN ? AND ?']=array($min_lat,$max_lat);
 $conditions['lng_value BETWEEN ? AND ?']=array($min_lon,$max_lon);
if (count($conditions)) {
 $parameters['conditions'] = join(' AND ', $conditions);
 }

how to use between condition???



33.6k
Accepted
answer

You have to use bound parameters to avoid SQL injections:

$placeholders = array();
$placeholders['status'] = $status;
$placeholders['featured'] = $featured;
$placeholders['min_lat'] = $min_lat;
$placeholders['max_lat'] = $max_lat;
$placeholders['min_lon'] = $min_lon;
$placeholders['max_lon'] = $max_lon;

$conditions = array();
$conditions[] = 'status = :status:';
$conditions[] = 'is_featured = :featured:';
$conditions[] = 'lat_value BETWEEN :min_lat: AND :max_lat:';
$conditions[] = 'lng_value BETWEEN :min_lon: AND :max_lon:';

$parameters = array();
$parameters['conditions'] = join(' AND ', $conditions);
$parameters['bind'] = $placeholders;

$result = Model::find($parameters);