We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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???



34.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);