seran128 Posted November 30, 2006 Share Posted November 30, 2006 I found a great Google maps API PHP tools but I am having problems getting it to work with my DB. I know the Query works because it has been tested in Navicatthe link to the tools is http://www.system7designs.com/codebaseI need to pull data from a db ond populate the function like they do below. My code is[code=php:0] <? $sql="select * from gs_location WHERE date > NOW() order by date"; echo $sql; $result=mysql_query($sql,$connection) or die(mysql_error()); while($row=mysql_fetch_array($result)) { $map->addAddress('$row['address1'],$row['city'],$row['state'] $row['zip']'); } $map->showMap(); ?>[/code]their sample code is[code=php:0]<?php /*** Showing valid points table/list with Phoogle Maps* class developed by Justin Johnson <justinjohnson@system7designs.com>*/require_once 'phoogle.php';$map = new PhoogleMap();$map->setAPIKey("ABQIAAAA0ksKqHM3yT_xmOPe0DANGRRMlCWGe88WcLmN582t1mFB9gpW6hTvRlzTS-LCJ8nFoD2AGi5vq0X-Yg");?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml"> <head> <? $map->printGoogleJS(); ?> </head> <body> <? $map->addAddress('208 Dingler Ave, Mooresville, NC 28115'); $map->addAddress('210 Doster Ave, Mooresville, NC 28115'); $map->addAddress('300 Dingler Ave, Mooresville, NC 28115'); $map->showMap(); ?> <h3>The following points are displayed on the map:</h3> <h4>(displayed using a table with an id of "my_table")</h4> <? $map->showValidPoints("table","my_table"); ?> <h4>(dispayed using an unordered list with an id of "my_list")</h4> <? $map->showValidPoints("list","my_list"); ?> </body></html>[/code] Quote Link to comment Share on other sites More sharing options...
paul2463 Posted November 30, 2006 Share Posted November 30, 2006 I dont really understand what you are after, but I will point something out[code]$sql="select * from gs_location WHERE date > NOW() order by date"; [/code]As long as all the entries in your table are in the futute it should pull them out. date > NOW() are dates in the future.. Quote Link to comment Share on other sites More sharing options...
seran128 Posted November 30, 2006 Author Share Posted November 30, 2006 Yes all dates are in the futureThe problem isin the $map->addAddress('$row['address1'],$row['city'],$row['state'] $row['zip']');Parse error: syntax error, unexpected T_STRINGMy quotes are messed up Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 30, 2006 Share Posted November 30, 2006 $map->addAddress('$row['address1'],$row['city'],$row['state'] . " " . $row['zip']'); Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 30, 2006 Share Posted November 30, 2006 [quote author=seran128 link=topic=116812.msg476243#msg476243 date=1164897770]The problem isin the $map->addAddress('$row['address1'],$row['city'],$row['state'] $row['zip']');Parse error: syntax error, unexpected T_STRINGMy quotes are messed up[/quote]Indeed they are ;)Try this instead:[code]<?php$map->addAddress("$row[address1],$row[city],$row[state] $row[zip]");?>[/code] Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 30, 2006 Share Posted November 30, 2006 Fix here I think, after seeing obsidians code:$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']); Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 30, 2006 Share Posted November 30, 2006 [quote author=Jocka link=topic=116812.msg476268#msg476268 date=1164898982]Fix here I think, after seeing obsidians code:$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);[/quote]Jocka, if you look at the sample code, it's wanting one parameter with the whole address as a string. You've got to parse all the variables into a readable address for it, thus my solution posted ;)[code]<?php$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");?>[/code] Quote Link to comment Share on other sites More sharing options...
Jocka Posted November 30, 2006 Share Posted November 30, 2006 .. .. oh ... yea... my appologies. lol, a long morning over in my neck of the woods :P Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 30, 2006 Share Posted November 30, 2006 [quote author=Jocka link=topic=116812.msg476285#msg476285 date=1164899694].. .. oh ... yea... my appologies. lol, a long morning over in my neck of the woods :P[/quote]Hehe... oh, yea, I completely understand that feeling... lol. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted November 30, 2006 Share Posted November 30, 2006 To get to googles format, the commas will have to become part of the string:[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted November 30, 2006 Share Posted November 30, 2006 [quote author=mainewoods link=topic=116812.msg476434#msg476434 date=1164916005]To get to googles format, the commas will have to become part of the string:[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]Haha... what is it with people rewriting the same solution over and over again today? lol[/quote] Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 1, 2006 Share Posted December 1, 2006 My solution is different to your solution obsidian, your's looks like this:[code]$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);[/code]mine looks like this:[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]--yours passes multiple parameters separated by commas while mine passes one string parameter with commas as part of the string. That's what the example from google was formatted as, not multiple parameters. I couldn't tell from the posts whether the problem was solved or not so that's why I submitted my answer which [i]is different [/i] than yours.From Google sample code:[code]$map->addAddress('208 Dingler Ave, Mooresville, NC 28115');[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 1, 2006 Share Posted December 1, 2006 [quote author=mainewoods link=topic=116812.msg477087#msg477087 date=1164993023]My solution is different to your solution obsidian, your's looks like this:[code]$map->addAddress($row['address1'],$row['city'],$row['state'] . " " . $row['zip']);[/code]mine looks like this:[code]$map->addAddress($row['address1'] . ', ' . $row['city'] . ', ' .$row['state'] . " " . $row['zip']);[/code]--yours passes multiple parameters separated by commas while mine passes one string parameter with commas as part of the string. That's what the example from google was formatted as, not multiple parameters. I couldn't tell from the posts whether the problem was solved or not so that's why I submitted my answer which [i]is different [/i] than yours.From Google sample code:[code]$map->addAddress('208 Dingler Ave, Mooresville, NC 28115');[/code][/quote]Not true at all. Look closely at my posts. You need to read the [b]whole[/b] of it before you branch off on a tangent ;) . [b]Both[/b] my posts that have code written are passing one string with all the variables within it, [i]just like the sample code requires[/i]! In fact, I'll quote my response to Jocka where it sounds like you got your solution from lol:[quote author=obsidian link=topic=116812.msg476281#msg476281 date=1164899575]Jocka, if you look at the sample code, it's wanting one parameter with the whole address as a string. You've got to parse all the variables into a readable address for it, thus my solution posted ;)[code]<?php$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");?>[/code][/quote]Now, back to my original statement... What's with everyone rewriting the same solution over and over? Haha :D Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 1, 2006 Share Posted December 1, 2006 I copied that from your post obsidian, I guess from the wrong part of the post(oops). Getting confused with all that jumping in and out of single quotes, double quotes, and whatnot is one of the easiest mistakes to make. Causes me more php and javascript parse errors than anything. Isn't the way you wrote it supposed to be poor coding practice because there should be single quotes around the variable names between the []s:[code]<?php$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");?>[/code]--recommended instead?[code]<?php$map->addAddress("$row['address1'], $row['city'], $row['state'] $row['zip']");?>[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 1, 2006 Share Posted December 1, 2006 [quote author=mainewoods link=topic=116812.msg477138#msg477138 date=1164997391]...Getting confused with all that jumping in and out of single quotes, double quotes, and whatnot is one of the easiest mistakes to make. Causes me more php and javascript parse errors than anything.[/quote]I [b]completely[/b] understand how that causes problems. I will admit that getting the hang of quotes in different languages is about the hardest thing for me, too ;)[quote author=mainewoods link=topic=116812.msg477138#msg477138 date=1164997391]Isn't the way you wrote it supposed to be poor coding practice because there should be single quotes around the variable names between the []s:[code]<?php$map->addAddress("$row[address1], $row[city], $row[state] $row[zip]");?>[/code]--recommended instead?[code]<?php$map->addAddress("$row['address1'], $row['city'], $row['state'] $row['zip']");?>[/code][/quote]Actually, that's an excellent question. If you try both the strings you posted above, you'll actually get warnings for your second one. When you're within double quotes, you don't need any singles to delimit the keys in your array. If you like to keep consistent, though, use brackets around each variable, and you can then print them as you would outside of quotes:[code]<?php$map->addAddress("{$row['address1']}, {$row['city']}, {$row['state']} {$row['zip']}");?>[/code]Nice and confusing, isn't it? :D Quote Link to comment Share on other sites More sharing options...
mainewoods Posted December 1, 2006 Share Posted December 1, 2006 I was thinking and I thought that leaving the single quotes off of the index would be more of a problem with javascript than php because in js it could then easily resolve to an actual variable defined earlier in the program, ie:[code]jsvar[string][/code]could be interpreted as a varaible named string defined earlier in the js or as the string 'string' which would then be the array index name. But in php:[code]$phpvar[indexstring];[/code]--seems more safe - no $ in between the [] so it can't be interpreted as a variable, but is there some constants preprocessor feature of php that could still cause a problem? I've been dutifully putting those single quotes in my php array references and it would be nice if I could give that up and still be safe. Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 4, 2006 Share Posted December 4, 2006 [quote author=mainewoods link=topic=116812.msg477281#msg477281 date=1165013167][code]$phpvar[indexstring];[/code]--seems more safe - no $ in between the [] so it can't be interpreted as a variable, but is there some constants preprocessor feature of php that could still cause a problem? I've been dutifully putting those single quotes in my php array references and it would be nice if I could give that up and still be safe.[/quote]Really, it depends on how much of a stickler you are for your code. If you leave off the quotes from your array key names within double quotes, that is correct syntax. However, if you leave them off outside of double quotes, your script will throw warnings. Your code will still function properly, and if you have all error suppression turned on, you may never know there is an issue, but PHP will [i]assume[/i] that you are trying to name a key, and it will parse it as such, but it will also throw a warning to the screen. Quote Link to comment Share on other sites More sharing options...
suess0r Posted February 1, 2007 Share Posted February 1, 2007 i put all my variables in an array to make a single variable to call the map with...[quote]$tmpq = array(); $fulladdress= $address; $tmpq[] = ","; $tmpq[] .= $city; $tmpq[] .= ","; $tmpq[] .= $state; $tmpq[] .= $zip; $fulladdress .= implode(' ',$tmpq); $map->addAddress($fulladdress);[/quote]that's how i did it b/c i already had those variables stored in my DB so just combine it in the map format and voolah. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.