mattc_uk Posted June 12, 2012 Share Posted June 12, 2012 Is is possible to write php code whereby it will contain a url but part of the url address is extracted from a MySQL database field? What would be the right coding for this? i.e. print "<a href=\"http://www.mysite.com/.... ['database field name']... /more of url address\"</a>" Quote Link to comment Share on other sites More sharing options...
DanielHardy Posted June 12, 2012 Share Posted June 12, 2012 echo '"www.google.com/".$your_field_from_database."therestofyoururl.com"'; Quote Link to comment Share on other sites More sharing options...
Jessica Posted June 12, 2012 Share Posted June 12, 2012 echo '"www.google.com/".$your_field_from_database."therestofyoururl.com"'; Because you have single quotes around the whole thing, that won't work. echo "www.google.com/{$your_field_from_database}therestofyoururl.com" Would work and remove the concatenation. Or use single quotes and concat. OP, if you're stuck post actual code. Quote Link to comment Share on other sites More sharing options...
DanielHardy Posted June 15, 2012 Share Posted June 15, 2012 Because you have single quotes around the whole thing, that won't work. echo "www.google.com/{$your_field_from_database}therestofyoururl.com" Would work and remove the concatenation. Or use single quotes and concat. Oops, right you are. Simply remove the single quotes so it becomes: echo "www.google.com/".$your_field_from_database."therestofyoururl.com"; Or use jesirose' solution. So you actually know a little about what is going on here, concatenation involves printing one or more strings when they have other things inbetween them. The concatenation operator is the " . " dot simple you see above, which basically means "and". 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.