Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

198
Views
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

over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

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>';
over 4 years ago · Santiago Trujillo Report

0

Just mismatched quotes.

There're many ways to mix PHP and HTML and you've chosen a hard syntax. Please compare with e.g.:

<?php foreach($foo as $row) { ?>
    <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>
<?php }

BTW, your are injecting raw text into HTML, beware that it can break your markup any time.

over 4 years ago · Santiago Trujillo Report

0

Your quotes are all over the place. You open a string variable with single quotes so every time you use single quotes unescaped in the string you just created will be interrupted.

It should be like this: <a href="read.php?id='.$row['id'].'" ... >

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!