Jump to content

converting query result into a hyperlink


mikalchristian

Recommended Posts

Hello, I am new to the board and PHP. I created a simple store locator app with PHP. It pulls the info from a database. I want to  take the website field from the table, once it is returned from the query, and have it print out a a hyperlink.

Please help.

 

Thanks, I have posted most of the relevant code.

 

 

<?php  if (isset ($stores)) {    if (!empty ($stores)) {     

echo '<p><strong>' . count ($stores) . ' results were found.</strong></p>';    foreach ($stores as $value) {       

echo '<p><strong>' . $value['name'] . '</strong><br />';     

echo $value['address'] . '<br />';     

echo $value['town'] . ', ' . $value['state'] . ' ' . $value['postal'];     

echo ' <a target="_blank" href="http://maps.google.com/maps?q=',

        $value['address'], ' ', $value['town'], ', ', $value['state'], ' ',

        $value['postal'],'">Map this location</a><br />';     

echo 'Phone: ' . $value['phone'] . '<br />';

echo 'Website: ' . $value['website'] .  '<br />'; 

echo 'Email: ' . $value['email'] . '<br />';   

echo 'Hours: ' . $value['hours'] ;     

echo '</p>';      }    }

else {   

echo '<p><strong>No results found</strong></p>';  }  } 

?>

   

If this doesn't work, your $value array is probably empty, which would require figuring out why it's empty.

 

echo ' <a target="_blank" href="http://';
echo urlencode("maps.google.com/maps?q={$value['address']} {$value['town']} {$value['state']} {$value['postal']}");
echo '">Map this location</a><br />';

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.