PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jul 19, 2006 8:12 am
I'm totally at a loss of how to implement what I'm looking for. I'm trying to create markers for each value in the arrays for client locations and I don't know how to effectively do this. I was thinking to automatically create however many vars were needed for each address and that many functions in the load() function, but this doesn't seem like a good idea any more. I'm really not sure how I can get it to create markers for the 80 something elements in the array. Any help would be greatly appreciated.
Code: Select all
<!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>
<?php
//sets user filter var for everything
global $ufilter;
global $st_addr;
global $city;
global $state;
global $zip;
global $array_string;
global $forInfo;
global $x;
global $varString;
gloabl $addString;
//mysql connect
$link = mysql_connect('', '', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tiki', $link);
if (!$db_selected) {
die ('Can\'t use tiki : ' . mysql_error());
}
//init sales_code temporarily
$sales_code_query = "
SELECT
els_contact.sales_code
FROM els_contact
WHERE els_contact.username = 'jbutler'
LIMIT 1";
//returns the result set
$sales_code_ret = mysql_query($sales_code_query);
if (!$sales_code_ret) {
die('Invalid query: ' . mysql_error());
}
//parses the array and assigns a result to a new variable
while ($newArray = mysql_fetch_assoc($sales_code_ret)) {
$ufilter = $newArray['sales_code'];
}
$client_address_query = "
SELECT
els_client_data.address1,
els_client_data.city,
els_client_data.state,
els_client_data.zip
FROM els_client_data
WHERE els_client_data.sales_code = '047'";
//returns the result set
$client_addr_ret = mysql_query($client_address_query);
if (!$client_addr_ret) {
die('Invalid query: ' . mysql_error());
}
//parses the array and assigns a result to a new variable
while ($address_array = mysql_fetch_assoc($client_addr_ret)) {
$st_addr[] = $address_array['address1'];
$zip[] = $address_array['zip'];
$state[] = $address_array['state'];
$city[] = $address_array['city'];
$varString = "var address1 =<?php print '$st_addr[$x], $city[$x], $state[$x], $zip[$x]';?>";
$addString = 'address'.$x;
$x = $x+1;
}
//more array manipulation
$x = 0;
$forInfo = count($st_addr);
?>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Map Points</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAApRphKLi-UMuIcsRzk_R2lhRi_j0U6kJrkFvY4-OX2XYmEAa76BQ_x0ZBELZ5jM4CBA8l_aIEatdzlQ" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
'<?php echo $varString;?>;'
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
markAddress(<?php echo $addString;?>);
}
}
function markAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " not found");
} else {
map.setCenter(point, 7);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jul 19, 2006 11:22 am
Fixed with this, in case anyone cares.
Code: Select all
<?php
// sets user filter var for everything
global $ufilter;
global $st_addr;
global $city;
global $state;
global $zip;
global $array_string;
global $forInfo;
global $x;
global $varString;
$googlekey = "ABQIAAAApRphKLi-UMuIcsRzk_R2lhQ5zKf0btzt0igWTsX3gDpiKzjrthQd-7Wu8Rc539eM0oGgm9Fi5CnE1g";
//mysql connect
$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db('tiki', $link);
if (!$db_selected) {
die ('Can\'t use tiki : ' . mysql_error());
}
//init sales_code temporarily
$sales_code_query = "
SELECT
els_contact.sales_code
FROM els_contact
WHERE els_contact.username = 'jbutler'
LIMIT 1";
//returns the result set
$sales_code_ret = mysql_query($sales_code_query);
if (!$sales_code_ret) {
die('Invalid query: ' . mysql_error());
}
//parses the array and assigns a result to a new variable
while ($newArray = mysql_fetch_assoc($sales_code_ret)) {
$ufilter = $newArray['sales_code'];
}
$client_address_query = "
SELECT
els_client_data.address1,
els_client_data.city,
els_client_data.state,
els_client_data.zip
FROM els_client_data
WHERE els_client_data.sales_code = '047'";
//returns the result set
$client_addr_ret = mysql_query($client_address_query);
if (!$client_addr_ret) {
die('Invalid query: ' . mysql_error());
}
$results = Array();
//parses the array and assigns a result to a new variable
while ($address_array = mysql_fetch_assoc($client_addr_ret)) {
$results[$i++] = $address_array;
}
//more array manipulation
$x = 0;
$forInfo = count($st_addr);
?>
<!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>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=<? echo $googlekey; ?>" type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
var map = null;
var geocoder = null;
<?php
$key = 0;
foreach($results as $key => $contact) {
$results[$key][javavarname] = "address$key";
$varString = "var address$key = \"$contact[address1], $contact[city], $contact[state], $contact[zip]\";\n";
echo $varString;
$key++;
}
?>
function load() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
geocoder = new GClientGeocoder();
<?
foreach($results as $contact) {
echo "markAddress(" . $contact[javavarname] . ");\n";
}
?>
}
}
function markAddress(address) {
if (geocoder) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
// alert(address + " not found");
} else {
map.setCenter(point, 7);
var marker = new GMarker(point);
map.addOverlay(marker);
}
}
);
}
}
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 500px; height: 300px"></div>
</body>
</html>
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Wed Jul 19, 2006 11:47 am
That's a ton of code for volunteers to look through to find a problem. Can you edit your posts to just show the loop that is not working?
(#10850)
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jul 19, 2006 11:49 am
Oh, no, the second post is the working code. The first bit was the broken one, and I wanted to show the community how I fixed my problem.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Wed Jul 19, 2006 11:55 am
arborint wrote: That's a ton of code for volunteers to look through to find a problem. Can you edit your posts to just show the loop that is not working?
that's what I thought too... then I realized he already figured it out
hydroxide
Forum Commoner
Posts: 77 Joined: Mon Jun 05, 2006 9:53 am
Post
by hydroxide » Wed Jul 19, 2006 12:03 pm
it wasn't so much that one piece of my code wasn't working, I was just looking for an idea as to how to implement the loop to achieve my goal. Perhaps I should have been more clear... sorry