Passing PHP variable to onClick method
问题 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? 回答1: Yes you're trying to open a php tag inside a line of php. Do this echo '<a href="#" onclick="showFilm(' . $row['ID'] .')">' . $row['Title'] . '</a>'; There's also a closing </a> you missed