mysql - PHP & Laravel: ConvertingVARCHAR value to FLOAT in query -
i have stored in table 2 fields lat , long, these columns have datatype of varchar
now in laravel have following variables:
$ne_lat = 21.405122657695813; $ne_lng = -102.32061363281252; $sw_lat = 19.984311565790197; $sw_lng = -104.19652916015627;
wich want use in query compare against table data this:
$agencies = db::table('users') ->whereraw('lat < ? , lat > ? , long < ? , long > ?',[$ne_lat,$sw_lat,$ne_lng,$sw_lng])
i've tried cast this:
$agencies = db::table('users') ->whereraw('cast(lat float) < ? , cast(lat float) > ? , cast(long float) < ? , cast(long float) > ?',[$ne_lat,$sw_lat,$ne_lng,$sw_lng])
but doesn't display results (i'm not getting error messages since query shows in json) doesn't show up. doing wrong query?
thanks in advance
(int)(your value);
or can use:
intval(string)
here sample:
<?php echo intval(42); // 42 echo intval(4.2); // 4 echo intval('42'); // 42 echo intval('+42'); // 42 echo intval('-42'); // -42 echo intval(042); // 34 echo intval('042'); // 42 echo intval(1e10); // 1410065408 echo intval('1e10'); // 1 echo intval(0x1a); // 26 echo intval(42000000); // 42000000 echo intval(420000000000000000000); // 0 echo intval('420000000000000000000'); // 2147483647 echo intval(42, 8); // 42 echo intval('42', 8); // 34 echo intval(array()); // 0 echo intval(array('foo', 'bar')); // 1 ?>
Comments
Post a Comment