Concatenate var into ECHO. no way to do this? eclipse error

hey you guys, eclipse is throwing an error at me when I try to do this:

            if ($index === 0) { echo "<td><a href=''" . $col target='_blank'>$col</a></td>"; }
            else { echo "<td>$col</td>"; }

what am I doing wrong? I’ve tried almost all incarnations I can think of! putting the var in single quotes, double quotes, and many other things. the error is: multiple annotations found at this line. unexpected "/"

i’ve fixed the syntax error, but now the $col variable is not showing up in the web address when I click on the hyperlink. this is my code, and I’m a bit stuck:

            if ($index === 0) { echo "<td><a href=''.'$col' target='_blank'>$col</a></td>"; }
            else { echo "<td>$col</td>"; }

When using HTML in a string i like to use single quotes so that you dont have to escape the double quotes which are very often used inside HTML.

$html = '<a href="#">click</a>'; // this works fine

On the other hand writing queries i set the string between double qoutes for the same reason:

$querystring = "SELECT * FROM users WHERE email='[email protected]'";

Wit concatenating variables in php i like to keep the variables outside the qoutes and to use the concatenation operator (.). Example:

echo '<td>' . $col . '</td>';

If really necessary you can escape quotes in strings. Little example:

echo 'Please don\'t leave the door open'; 

While this website doesn’t highlight this the right way it would in your php editor.

after playing with this stupid thing through many incarnations, I have found the following to be acceptable to eclipse. I’m sorry to bother you guys with simplicity! =/

if ($index === 0) { echo "<td><a href='$col' target='_blank'>$col</a></td>"; }

thank you frank. I will look at what you posted later on. I simply went through trial and error due to frustration with an IDE. I’ve gone through this many times before with other IDE’s that suck.

I’m not sure your examples though, are relevant to my issue. But I will keep your words in my knowledgebase. thanks again Frank. =)

1 Like
1 Like

thank you ernie. =) your words are always wise.

Sometimes it is hard to understand the explanation.
Sometimes reworded a different way gives light to the problem.
Glad you get it now. Frank gave the answer. I just shed light on it a bit more…
Always nice to solve a programming puzzle.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service