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?

3
  • i think it is possible duplicate of How can I make a link from a <td> table cell Commented Jul 3, 2017 at 0:20
  • Your HTML structure is not valid. Put the <a> element inside the <td> Commented Jul 3, 2017 at 0:24
  • How exactly do you want the HTML to appear? Commented Jul 3, 2017 at 0:27

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.