0

I want to use this variable:

$id= $row['property_id'];

Inside this href after the equals sign after 'id'

echo "<td>""<a href='product_description.php?id='>" . $row['PropertyType'] . "</a></td>";

How can I do this? I think it may be a problem with escaping quotes but I can't seem to find a solution. I'm new to php and would appreciate the help

3
  • 1
    have you tried it just exactly the way you did with $row['PropertyType']? Commented Oct 20, 2016 at 6:28
  • This would also work for you--- "<td><a href='product_description.php?id=$id'> $row['PropertyType']</a></td>"; Commented Oct 20, 2016 at 6:54
  • Why don't you simply use echo "<td><a href='product_description.php?id={$row['property_id']}'>{$row['PropertyType']}</a></td>"; ? Commented Oct 20, 2016 at 7:02

3 Answers 3

1

Do it like this:

echo '<td><a href="product_description.php?id=' . $id . '" >' . $row['PropertyType'] . '</a></td>';

You should also think about echoing the data in the html, instead of echoing out html itself. It is a lot cleaner.

e.g. you can do the above like this:

<?php
   // your php, ready up the data. your $id and $row
?> <!-- close your php tag -->
<td>
   <a href="product_description.php?id=<?= $id ?>" >
      <?= $row['PropertyType'] ?>
   </a>
</td>

Note: that <?= $var ?> is equivalent to <?php echo $var ?>.

Sign up to request clarification or add additional context in comments.

1 Comment

This is a relatively expensive way of doing it.
0

You only need to put your variable same as PropertyType which you wrote. Please find below syntex:

echo "<td><a href='product_description.php?id=" . $id . "'>" . $row['PropertyType'] . "</a></td>";

Comments

0

I guess you need something like this (variable variables):

$var_id = 'id';
$$var_id = 'something';

print_r($id);
print_r($var_id);

Will give you

something
id

in output respectively. So you can use it like:

$var_id = $row['property_id'];
$$var_id = 'id';

echo '<td><a href="product_description.php?'.$var_id.'='.$id.'">'.$id.'</a></td>';

That will generate a link that leads to:

http://example.com/product_description.php?id=property_id

Or simply

$id= $row['property_id'];
echo '<td><a href="product_description.php?id='.$id.'">'.$id.'</a></td>';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.