I need to display a bunch of stores and the distance from a zip code. So I POST a zip code to the page and do:
if($zip){
$SQL= "SELECT store_name, store_zip, ROUND(zip_dist( store_zip,'".zip."',latitude,longitude)) as distance FROM t_stores";
}else{
$SQL= "SELECT store_name, store_zip, 0 as distance FROM t_stores";
}
$g-select_command = $SQL;
… but something is going wrong. It keeps acting as if I am not POSTing the zip code. If I add echo($SQL) immediately after, I get…
SELECT store_name, store_zip, 0 as distance FROM t_stores (which is the wrong $SQL)
I believe I must use some other method of passing the zip code, but how?
Just to correct the code:
if($zip){
$SQL= "SELECT store_name, store_zip, ROUND(zip_dist( store_zip,'".$zip."',latitude,longitude)) as distance FROM t_stores";
}else{
$SQL= "SELECT store_name, store_zip, 0 as distance FROM t_stores";
}
$g->select_command = $SQL;
The thing is…. it works perfectly well when I use this:
if($zip){
$SQL= "SELECT store_name, store_zip, ROUND(zip_dist( store_zip,'90210',latitude,longitude)) as distance FROM t_stores";
}else{
$SQL= "SELECT store_name, store_zip, 0 as distance FROM t_stores";
}
$g->select_command = $SQL;
(i.e. when I hardcode a number for $zip.) This suggests that the problem is how to allow a user to pass his zip code to the script. POST doesn't work. GET doesn't work either.
Wow! I got it to work!
I changed from POST to GET in my form and that works. Changed back to POST (just to check) and it fails again. That's some weird stuff!
When you used GET, the param become the part of URL and thus used with all round trips of grid.
When you used POST, it was there only for first time and not for successive ajax calls.
If you still want to use POST, you should persist that value in SESSION and use that session variable in select_command.