Ck Yong
Ck Yong

Reputation: 51

PHP echo problem

What is wrong in the following code?

<?php
    echo "<td class='column1'><a href='#' OnClick='windowpopup(". secure_base_url()`"product/item/". $itemid ."/); return false;'>$row->title</a></td>";?>
?>

Why doesn't a popup window come up?

Upvotes: 0

Views: 1567

Answers (3)

Russell Dias
Russell Dias

Reputation: 73282

Whats the value of $row->title. Also, using single quotes will print the variable name, rather than its value.

edit: Ahh so there is more. Shamittomar, seems to have fixed your problem =)

Upvotes: 0

shamittomar
shamittomar

Reputation: 46692

After OP Clarification:

After viewing hidden HTML, I must say here's how your code should look like:

<?php
echo "<td class='column1'><a href='#' OnClick='windowpopup(\"". secure_base_url() ."product/item/". $itemid ."/\"); return false;'>{$row->title}</a></td>";
?>

The reason is same though. You need to escape correctly and use double quotes for variables to expand in PHP.

Old Answer

Use this:

 echo "{$row->title}";

Or

 echo $row->title;

The PHP String Documentation says that:

"The most important feature of double-quoted strings is the fact that variable names will be expanded."

So, to expand variable names, either use double quotes and as precaution enclose them in {} OR do not use quotes at all.

Upvotes: 5

Jacob Relkin
Jacob Relkin

Reputation: 163228

String interpolation in PHP only works in double quotes.

Upvotes: 2

Related Questions