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!

Recommended Answers

All 6 Replies

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

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

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…

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

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

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?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.