Reputation: 13
I am using this code but it is giving me errors. How do I display the images in a table using php?
echo "<td>"."<img src=\"=View.php?image_id=$row['Id']>\""."</td>";
I am getting a syntax error, how can I fix this?
The error that I get is - Parse error: syntax error, unexpected
T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in
C:\xampp\htdocs\gallery_test\listImages.php on line 45
Thank You
Upvotes: 1
Views: 56
Reputation: 5933
Let's break it down:
echo "<td>"
. "<img src=\"=View.php?image_id=$row['Id']>\""
. "</td>";
First we need to fix the misplaced =
. After that, we need to fix the misplaced quote. Finally, wrap $row['Id']
in brackets to fix the syntax error. It should now look like this:
echo "<td>"
. "<img src=\"View.php?image_id={$row['Id']}\">"
. "</td>";
If you'll write it like this, you'd have less of a mess and it fixes the error. Clean and simple.
echo "<td><img src=\"View.php?image_id={$row['Id']}\"></td>";
When placing variables in strings it's recommended to wrap them in brackets to avoid syntax errors like these but also to keep your code looking clean.
Upvotes: 1
Reputation: 22731
Try this, You have string concatenation issue.
echo "<td><img src='View.php?image_id=".$row['Id']."' ></td>";
Upvotes: 0
Reputation: 44874
Try as
echo '<td><img src="View.php?image_id='.$row['Id'].'"></td>';
Upvotes: 0