0

So I am using php 5.6 for a project. I am printing data from a mySQL database into a table:

echo "<tr>
        <a href='javascript:movieCookieCreator()'  id='".$row["dir"]."'>
            <td>".$row["name"]."</td>
        </a>
        <td>".$row["genre"]."</td>
      </tr>";

the id tag in the code above is used to store a directory for a movie, however, the row and its elements are not appearing as links.

This is the raw HTML as it is printed,

<center>
<table>
<tr>
    <th>Title</th>
    <th>Genre</th>
</tr>
<tr>
    <a href='javascript:movieCookieCreator()'  id='/movies/Shrek.mp4'>
        <td>Shrek</td>
    </a>

why is it not a link? and can the id tag be used to store data for javascript functions?

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Todd Owen
  • 97
  • 1
  • 9

1 Answers1

1

Your HTML structure is not valid. If you want the entire table cell (<td>) to be clickable, try this instead...

?>
<tr>
    <td onclick="movieCookieCreator()" id="<?= htmlspecialchars($row['dir']) ?>"
        style="cursor:pointer">
        <?= htmlspecialchars($row['name']) ?>
    </td>
    <td><?= htmlspecialchars($row['genre']) ?></td>
</tr>
Phil
  • 157,677
  • 23
  • 242
  • 245