Forum Moderators: coopster
echo "<a href='http://$myrow[link]'>$myrow[place]</a>";
I usually use single quotes around my attributes when echoing or printing so I don't have to escape them.
I also don't use quotes around the MySQL field(i.e. [link])
Don't rightly know if my methods are correct, but it seems to work for me.
$this_link = $myrow["link"];
$this_place = $myrow["place"];
echo "<a href=\"http://$this_link]\">$this_place</a>";
Makes it a little easier to create and read the html.
If you use double-quotes, you can reference variables directly. If you use single quotes, you won't need to escape the double quotes, but PHP won't translate the variables. Whatever you prefer.
$this_link = $myrow["link"];
$this_place = $myrow["place"];
echo "<a href=\"http://$this_link]\">$this_place</a>";
Why not just use extract($myrow);?
I agree, this makes code much more readable.
WBF
Why not just use extract($myrow);?
Absolutely! I figured that would complicate my post.
What are the benefits of using the heredoc
Another benefit of using heredoc syntax is that it save you from having to escape any kind of quotes within your string.
Andreas
I also don't use quotes around the MySQL field(i.e. [link])
I'm pretty sure that this will cause an 'unknown define' warning to be generated. However, php just assumes that link is defined as 'link' so your code still works - but I wouldn't recommend it.
If your not seeing a warning yourself then you probably don't have the error level turned up - have a look in php.ini and put it all the way up to error_reporting = E_ALL for development work.
echo <<<END_OF_HTML
I like the Heredoc syntax too, but unfortunately it causes the syntax highlighting in Textpad to get completely confused. Anyone got a php syntax definition file for textpad that can handle it?Or know of a better editor to write php in?