0

Can anyone help me with this?

I need for select out the posts where type_lbiltank=1 from this SQL-sentence:

$query = sprintf("SELECT address, name, email, type_lbiltank, type_lbilut, type_lbilborst, type_pbilselv, type_pbilauto, lat, tlf, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",

This is from the Google Store Locator.

Thanks for help!

2
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by jkon
0

You must have a reason to do this. In most cases there are better performance solutions than select in a select. I you just want to get the results that have type_lbiltank=1 in first place just add it.

If in the other hand you want to filter the results programmatically just loop them and pass them in an array if type_lbiltank=1.

Just for mentioning select in a select results could be SELECT foo.address,foo.name - and so on - FROM ( - your original select- ) as foo WHERE foo.type_lbiltank = 1

0

But arent there a way where I can use WHERE type_lbiltank=1 at the end of the mysql command?

0

As I wrote …if you just want to get the results that have type_lbiltank=1 in first place, just add it , WHERE type_lbiltank=1 before HAVING…

0

Like this?
AS distance FROM markers WHERE type_lbiltank=1 HAVING distance

0

But when I'm going to get out the posts where type_lbiltank=1 and type_lbilborst=1 and type_lbilut=1, how can I do that? I can't get that to work..

Tried this one:

$query = sprintf("SELECT address, name, email, type_lbiltank, type_lbilut, type_lbilborst, lat, tlf, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM markers WHERE type_lbiltank=1 OR type_lbilborst=1 OR type_lbilut=1 HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",

But with no luck

0

In your comment you say “and” and in your code you wrote “or”. If you want the logical operator put “and” if you want to be or , put “or”. I am saying this with the best possible mood, wouldn’t be better to spend 10 minutes reading about basic MySql syntax than spending match more time asking?

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.