I have a MySQL database set up that visitors can search through that gives them a list of other people that live nearby. It has fields like Name, Address, City, State, and Zip Code. I have a script that will combine the variables $address, $city, $state, and $zip and create a link that displays a map of where the person lives. I can't figure out how to get the variables from the database rows. Here is the section of the script that builds the rows from the search results:
code:
$nr1=0;while ($row=mysql_fetch_array($res)){ $nr1++;print "<tr><td align='center'>$nr1</td><td align='center'>$row[1]</td><td align='center'><a href=$Mlink>$link$row[2]</a></td><td align='center'>$row[3]</td><td align='center'>$row[4]</td><td align='center'>$row[5]</td><td align='center'>$row[6]</td><td align='center'>$row[7]</td><td align='center'>$row[8]</td><td align='center'>$row[9]</td><td align='center'>$row[10]</td><td align='center'>$row[11]</td>";}
Here is the script that generates the MapQuest link:
code:
<?php// Variables..: 4 character strings; address, city, state, // zip // example of use..: // echo getMquest('374 Center St', 'Winona', 'MN','55987'); // echo getMquest('374 Center St', 'Winona', 'MN','55987', 'link string'); // Above would create a link to MapQuest.com that would //pull up a map of that location. function getMquest($address, $city, $state, $zip, $link = '') { //Store the original address $Address = array( 'address' => $address , 'city' => $city , 'state' => $state , 'zip' => $zip ); //Initialize local variables. $Mlink = ""; //Return value //Strip periods, commas, leading, and tailing spaces from address, city, $address = trim($address); $address = str_replace('.','',$address); $address = str_replace(',','',$address); $address = str_replace(' ','+',$address); $city = trim($city); $city = str_replace('.','',$city); $city = str_replace(',','',$city); $city = str_replace(' ','+',$city); $zip = trim($zip); $state = trim($state); //Combine the given data into a url that will link to mapquest $Mlink = "http://www.mapquest.com/maps/map.adp?country=US&address=" . $address . "&city=" . $city . "+&State=" . $state . "&Zip=" . $zip . "&submit.x=0&submit.y=0"; switch(true){ case($link == ''): $Mlink = "<a href=$Mlink>" . $Address['address'] . "<br>" . $Address['city'] . ", " . $Address['state'] . "<br>" . $Address['zip'] . "</a>"; break; case($link != ''): $Mlink = "<a href=$Mlink>$link</a>"; break; } return $Mlink; } ?>
This is what the results look like in the column that contains the map link 'MAP': <a href=>MAP</a>
I can't figure out how to define the variables that are needed to create the links since they are contained in $row[1], $row[2], etc.
Can somebody offer any help as to how I can get this to work?
John