-2

I know is a stupid question but well i am trying so hard but i can't figure out on where i am missing the comma i am totally confused ,The below code is giving me an error.

it would be great if someone can help me out with a referencing on comma and tips / Tricks on them :)

i tried replacing the commas in different places but still it didn't worked out.

   <td><?php echo <a href="test1.php?id=<?php echo $row['ID'];?>"/>Download! ?></a></td>

Thanks :)

user3184290
  • 19
  • 1
  • 7

5 Answers5

1

It has to be:

<td>
    <?php
        echo '<a href="test1.php?id=' . $row['ID'] . '">Download!</a>';
    ?>
</td>

Alternatively:

<td>
    <a href="test1.php?id=<?=$row['ID']?>">Download!</a>
</td>
jkemming
  • 722
  • 12
  • 19
0
<td><a href="test1.php?id=<?php echo $row['ID'];?>"/>Download!</a></td>

Try this one

0

One important thing to remember is that you do not have to use echo to output static HTML content, only for the dynamic part, the variable in you case. The correct version looks like:

<td><a href="test1.php?id=<?php echo $row['ID'];?>"/>Download!</a></td>
Zoli Szabó
  • 4,366
  • 1
  • 13
  • 19
0

The immediate approach typically would be that:

<td><a href="test1.php?id=<?php echo $row['ID'];?>">Download!</a></td>

Often it can be shortened, depending on your php configuration:

<td><a href="test1.php?id=<?= $row['ID'] ?>">Download!</a></td>

To me the second form is more readable, thus my personal preference.

arkascha
  • 41,620
  • 7
  • 58
  • 90
0

There is one redundant echo with opening/closing php tags, also you wrongly self-close the a tag.

In your html template it is sufficient to write:

<td>
    <a href="test1.php?id=<?php echo $row['ID'];?>">Download!</a>
</td>

Code between <?php and ?> is php code which is "injected" in html.

$row is array and with $row['ID'] you get value of specific key from array which is ID. You can access the value on this key also with double quotes like $row["ID"] there is no difference, because you want to access the key which is referenced by string with value ID. You can embrace string with single or double quotes. More on strings in php manual: http://php.net/manual/en/language.types.string.php

When you want to use same quotes in string you have to escape it like

<?php 
echo "This is double quote: \"."; //result: This is double quote: ".
?>

same with single quote:

<?php 
echo 'This is single quote: \'.'; //result: This is single quote: '. 
?>

You can echo some other string with value from array for example:

<?php echo "this row has id: " . $row["ID"]; ?>

so you concatenate string and value with the period/dot.

Or you can access value of variable in string like:

<?php
$rowId = 1;
echo "this row has id: $rowId"; //result: this row has id: 1
?>

But it is hard to spot it and many IDE's will not highlight it. Better can be to concatenate it with period (echo "this row has id: " . $rowId;).

You can also specify value from array, but you have to enclose it with {} so the php engine know that it is array variable no the literal

<?php echo "this row has id: {$row["ID"]}"; ?>

or object property:

<?php echo "this row has id: {$row->id}"; ?>

But it can also be hard to spot it when you write it like this.

When you want to literally write all this code you can enclose it by single quotes:

<?php
echo '<?php echo "this row has id: {$row["ID"]}"; ?>'; //result: <?php echo "this row has id: {$row["ID"]}"; ?>
?>

or escape all double quotes and dollar sign $ and the result will be same:

<?php echo "<?php echo \"this row has id: {\$row[\"ID\"]}\"; ?>"; ?>

speto
  • 3
  • 5