<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create an Onclick event using php</title>
<style>
th,td {
border:1px #666 solid;
cursor:pointer;
}
</style>
</head>
<body>
<table style="width:200px; border-collapse: collapse;" align="center">
<tr>
<th onclick="alert('TH ID')">ID</th>
<th onclick="alert('TH Name')">Name</th>
</tr>
<?php
for ($i =1 ; $i<=3 ; $i++ ) {
echo "<tr><td onclick=\"alert('a'+$i)\">$i</td><td onclick=\"alert('b'+".$i.")\">$i</td></tr>";
}
?>
</table>
</body>
</html>