I'm pulling some data from MySQL using PHP and need to pass an ID as a parameter to a onClick() method.
while($row = mysql_fetch_array($result))
{
echo '<a href=# onclick="showFilm('<?php echo $row['ID'] ?>')">' .
$row['Title'];
}
I'm getting a syntax issue on the echo
statement. What am I doing wrong?
Your HTML
Your jQuery
Yes you're trying to open a php tag inside a line of php. Do this
There's also a closing
</a>
you missed. Ideally you wouldn't use onclick but that's not what you asked about and it won't break with it there. Oh, and the value of href should be quoted.So, since you ask, let's say you wanted to use jQuery instead of onclick
You would need to include the jquery library. See this http://docs.jquery.com/How_jQuery_Works and you would need your own script before
</body>
or in a separate js file.Another way:
Dont forget to close the a tag at the end. Didn't see it in your code.