Skip to content
Advertisement

Adding HTML codes inside PHP

I’m trying to add a view button to my table but I’m getting a syntax error, unexpected href. Seems like I’m wrong with the formatting. Still trying to learn PHP but is it possible to add href to the table?

Here’s my code:

while($row = mysqli_fetch_array($result))
{
    $output .= '
        <tr>
            <td>'.$row["name"].'</td>
            <td>'.$row["temperature"].'</td>
            <td>'.$row["phoneno"].'</td>
            <td> '<a href='read.php?id='. $row['id'] .'' title='View Record' data-toggle='tooltip'><i class='fa fa-eye' style='font-size:30px; color: black;''></i></a>';' </td>
        </tr>
    ';
}
echo $output;

And here’s the image for the color coding that seems wrong.

sublime

Advertisement

Answer

It is because you’re using single quotes to delimit your strings while using single quotes in the strings to denote values.

This –

<td> '<a href='read.php?id='. $row['id'] .'' title='View Record' data-toggle='tooltip'><i class='fa fa-eye' style='font-size:30px; color: black;''></i></a>';' </td>

Should be this –

<td><a href="read.php?id='. $row['id'] .'" title="View Record" data-toggle="tooltip"><i class="fa fa-eye" style="font-size:30px; color: black;"></i></a></td>';
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement