php/sql select all

38 views
Skip to first unread message

mwcog mwcog

unread,
Jun 15, 2011, 11:45:13 AM6/15/11
to google-map...@googlegroups.com
 So i'm new to all this and have, what should be, and ease question.

I've successfuly modified the store locator example (http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html) to fit my data.  I've also added a dropdown menu to run a select statement on the .xml page. It works when I pass the following address (......_xml_domnew.php?lat=39&lng=-77&radius=10000&Juris=PG, note the PG value) to the xml.  However, what do i do to select all Juris (I have many Juris values).  Here is the select statement I use:


// Search the rows in the markers table
$query = sprintf("SELECT Juris, Cost, lat, lng, ( 3959 * acos( cos( radians('%s') ) * cos( radians( lat ) ) * cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) * sin( radians( lat ) ) ) ) AS distance FROM ARP_projects WHERE Juris = '$Juris"",
 mysql_real_escape_string($Juris),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($radius));

What do I need to do to select all records in the Juris Column?

Any help?

Barry Hunter

unread,
Jun 16, 2011, 6:02:39 AM6/16/11
to google-map...@googlegroups.com
Do you mean get all rows, regardless of what the value of Juris is?

... then just remove the WHERE clause from the SQL statement.

Or do you mean get a list of values, to be able to draw the dropdown?

... the use of GROUP BY or DISTINCT in mysql should be investigated.

(also note that the use of sprintf, the values after the initial
string (containgn the sql statement) define what gets put in place of
the placeholders (%s) - it doesnt look like the placeholders and
values line up in your example.
http://php.net/sprintf )

> --
> You received this message because you are subscribed to the Google Groups
> "Google Maps JavaScript API v3" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-maps-js-api-v3/-/I_fQJmEgFQMJ.
> To post to this group, send email to google-map...@googlegroups.com.
> To unsubscribe from this group, send email to
> google-maps-js-a...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/google-maps-js-api-v3?hl=en.
>

davie

unread,
Jun 18, 2011, 6:01:21 PM6/18/11
to Google Maps JavaScript API v3
Hi
Try

// Search the rows in the markers table
$query = sprintf("SELECT Juris, Cost, lat, lng,, ( 3959 *
acos( cos( radians('%s') ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) *
sin( radians( lat ) ) ) ) AS distance FROM ARP_projects WHERE Juris =
%s HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($Juris),
mysql_real_escape_string($radius));

Regards Davie

davie

unread,
Jun 18, 2011, 6:08:58 PM6/18/11
to Google Maps JavaScript API v3
Hi
Sorry one comma too many .It happens when you cut and paste in a
hurry.

// Search the rows in the markers table
$query = sprintf("SELECT Juris, Cost, lat, lng, ( 3959 *
acos( cos( radians('%s') ) * cos( radians( lat ) ) *
cos( radians( lng ) - radians('%s') ) + sin( radians('%s') ) *
sin( radians( lat ) ) ) ) AS distance FROM ARP_projects WHERE Juris =
%s HAVING distance < '%s' ORDER BY distance LIMIT 0 , 20",
mysql_real_escape_string($center_lat),
mysql_real_escape_string($center_lng),
mysql_real_escape_string($center_lat),
mysql_real_escape_string($Juris),
mysql_real_escape_string($radius));

Regards Davie


mwcog mwcog

unread,
Jun 20, 2011, 11:48:44 AM6/20/11
to google-map...@googlegroups.com
I mean all rows regardless of what the value of Juris is (someone choose to show all Juris).   So I need to write some sort of if/then statement to call the WHERE Juris ="%S'?

Andrew Leach

unread,
Jun 20, 2011, 11:52:39 AM6/20/11
to google-map...@googlegroups.com

As others have said, you are asking about SQL, not the Maps API. This
is wrong group for your question.

However, you might want to investigate the LIKE keyword.

mwcog mwcog

unread,
Jun 20, 2011, 11:55:15 AM6/20/11
to google-map...@googlegroups.com
Thanks for you're reply!

However, i still don't get any records when I type something like http://www.anacostia.net/maps/anacostia_xml_domnew.php?lat=39&lng=-77&radius=255

but

http://www.anacostia.net/maps/anacostia_xml_domnew.php?lat=39&lng=-77&radius=255&Juris=PG
works fine.  Any other suggestions.

Rossko

unread,
Jun 20, 2011, 11:57:19 AM6/20/11
to Google Maps JavaScript API v3
> Any other suggestions.

Sure.

Ask your question in a MySQL group.

See your other thread
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/e5ed8e27e1de50cd
(multiple posts do make it difficult for yourself)

If you don't want to use a WHERE clause, don't use a WHERE clause i.e.
omit it from your query.

mwcog mwcog

unread,
Jun 20, 2011, 2:08:01 PM6/20/11
to Google Maps JavaScript API v3
Thanks for the suggestion. Didn't realize i was asking a non-maps api
question. Sorry, learning as I go! Off to find a sql group.

On Jun 20, 11:52 am, Andrew Leach <andrew.leac...@gmail.com> wrote:

davie

unread,
Jun 20, 2011, 5:27:33 PM6/20/11
to Google Maps JavaScript API v3
Hi
Your first url only has 3 parameters your second has 4
The SQL query requires 4 that is how the first one does not work.
As the others said this is not a Mysql group but a tip Try your SQL
queries with phpmyadmin to ensure you get the required results.
Once you have done this you can incorporate it in your php file
Regards Davie

On Jun 20, 4:55 pm, mwcog mwcog <mwcog....@gmail.com> wrote:
> Thanks for you're reply!
>
> However, i still don't get any records when I type something likehttp://www.anacostia.net/maps/anacostia_xml_domnew.php?lat=39&lng=-77...
>
> but
>
> http://www.anacostia.net/maps/anacostia_xml_domnew.php?lat=39&lng=-77...
Reply all
Reply to author
Forward
0 new messages