php - Query based on dropdown selection with google maps GeoLocation -
i trying run query based on dropdown value posted html can't manage work.
this html:
<form action="" method="post"> <select name="nearest"> <option name="distance" value="5">5km</option> <option name="distance" value="10">10km</option> <option name="distance" value="25">25km</option> <option name="distance" value="50">50km</option> <option name="distance" value="100">100km</option> </select> <input type="submit" name="filternow" value="filter" id="filterbutton"> </form>
this php:
if (isset($_post['filternow'])){ $selecteddistance = $_post['nearest']; $q = "select id, name, image_url, description, price, lat, lng, rating, owner, free, city, round(( 6371 * acos( cos( radians(" . $_post['userlat'] . ") ) * cos( radians( lat ) ) * cos( radians( lng ) - radians(" . $_post['userlng'] . ") ) + sin( radians(" . $_post['userlat'] . ") ) * sin( radians( lat ) ) ) ), 2) distance places having distance < " . $selecteddistance . " order distance asc"; $res1 = mysqli_query($linknew, $q); } echo "<h2>nearest places</h2>"; while($row1 = mysqli_fetch_array($res1)){ echo "<h2>" . $row1[1] . "</h2><br />"; }
if replace $selecteddistance number , remove form in html , if-loop in php, shows me places within amount of kilometers, doesnt work dropdown
this may causing issue.
the option tag not have name attribute change them :-
<option value="5">5km</option>
also if ever issues data passed script using $_post or $_get dump $_post/get onto browser , have @ in using var_dump($_post);
so before line add var_dump
var_dump($_post); if (isset($_post['filternow'])){
and $_post displayed on browser, or preference
echo '<pre>' . print_r($_post, true) . '</pre>'; if (isset($_post['filternow'])){
if probelem not obvious add dumped output question , can have guess.
Comments
Post a Comment