select_command – Mysql function

Questionsselect_command – Mysql function
Richard asked 12 years ago

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?

3 Answers
Richard answered 12 years ago

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.

Richard answered 12 years ago

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!

Abu Ghufran answered 12 years ago

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.

Your Answer

14 + 2 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.



How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?