wright67uk Posted May 16, 2011 Share Posted May 16, 2011 Can anybody help me to echo a url? Id like to have http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|SG1+4PP&sensor=false but to have the postcode as a variable which has been fetched from mysql <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <?php include($_SERVER['DOCUMENT_ROOT'].'/include/db.php'); ?> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> <!-- --> </style> <link href="header.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="banner"> <div id="bannerleft"></div> <div id="logo"></div> <div id="bannerright"><div id="navbar" title=""> <div id="b1"><p class="centre"><a href="index.html">Directory</a></p></div> <div id="b2"><p class="centre"><a href="business.html">Add Your Business</a></p></div> <div id="b3"><p class="centre"><a href="contact.html">Contact Us</a></p></div> </div><!-- end of navbar--> </div><!--end of bannerright--> </div><!-- end of banner--> <div id="listhold"> <?php $subtype = $_GET['subtype']; echo "<h1>$subtype</h1>"; $result = mysql_query("SELECT name, phone, email, WebAddress, postcode FROM business WHERE subtype ='$subtype' AND confirmed ='Yes' ORDER BY name"); echo mysql_error(); while($row = mysql_fetch_array($result)) { echo $row['name'] . "<br>"; echo $row ['phone'] . "<br>"; echo $row['email'] . "<br>"; echo $row['WebAddress'] . "<br>"; echo $row['postcode'] . "<br>" . "<br>"; echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; } ?> </div> </body> </html> The above returns an error; Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/ Share on other sites More sharing options...
requinix Posted May 16, 2011 Share Posted May 16, 2011 For that error, forum highlighting software (such as the one used to highlight the code in your post) will often give a bit, giant, red-colored clue as to where the problem lies. In this case it shows where a problem is. What line number does the error message refer to? And did you post the exact code? Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216219 Share on other sites More sharing options...
wright67uk Posted May 16, 2011 Author Share Posted May 16, 2011 and in this case as I have several lines of my code in red, im asking if anyone can help me. Please. Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216221 Share on other sites More sharing options...
wright67uk Posted May 16, 2011 Author Share Posted May 16, 2011 I have tried; echo <a href="http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|. str_replace(' ','+',$row['postcode'])&sensor=false">; but then I get unexpected '<' ... error Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216228 Share on other sites More sharing options...
jcbones Posted May 16, 2011 Share Posted May 16, 2011 //notice the following line: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right. //Now, notice this line: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',{$row['postcode']})&sensor=false'>"; //<-brackets look right now. This is because of how php handles array values in double quoted strings. //you can either break out of the string, or you can enclose them in curly braces, or you can just not put the key inside of single quotes. Any of the 3 will work. Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216230 Share on other sites More sharing options...
anupamsaha Posted May 17, 2011 Share Posted May 17, 2011 Change: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right. To: //Now, notice this line: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|".str_replace(' ','+',$row['postcode'])."&sensor=false'>"; Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216383 Share on other sites More sharing options...
jcbones Posted May 17, 2011 Share Posted May 17, 2011 Change: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|.str_replace(' ','+',$row['postcode'])&sensor=false'>"; //<-the brackets around $row['postcode'] doesn't look right. To: //Now, notice this line: echo "<a href='http://maps.google.com/maps/api/staticmap?zoom=15&size=400x400&markers=color:blue|label:EXAMPLE|".str_replace(' ','+',$row['postcode'])."&sensor=false'>"; ^correct, way to many hours looking at pixels. Quote Link to comment https://forums.phpfreaks.com/topic/236580-parsing-a-url-and-unexpected-t_encapsed_and_whitespace/#findComment-1216418 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.