title: PHP/MySQL OnClick Update MySQL
body: <p>Need to update a hitcount field in a MySQL table when a user clicks on a banner ad. Have the random ad display script working but can't figure out how to update the table when they click..assuming will have to pass the ID to Ajax but no idea how to approach it? Code is below: </p>
  
  <pre><code>include 'connection.php';
  $query = "select * from ads where adtype = 'small' and status = 'yes' ORDER BY RAND() LIMIT 3";
  $result = mysql_query($query) or die(mysql_error());
  
  $num_results = mysql_num_rows($result);
  if ($num_results !="0")
  {
  for($i=0;$i&lt;$num_results;$i++)
  {
      $row = mysql_fetch_array($result);
  
      $client = htmlspecialchars(stripslashes($row['client']));
      $link = htmlspecialchars(stripslashes($row['link']));
      $filename = htmlspecialchars(stripslashes($row['filename']));
      $id = $row['id'];
      echo "&lt;tr&gt;";
      echo "&lt;td&gt;";
      echo '&lt;a href="';
      echo $link;
      echo '"&gt;&lt;img src="thimg/';
      echo $filename;
      echo '" alt="';
      echo $client;
      echo '"&gt;&lt;/a&gt;';
      echo "&lt;/td&gt;";
      echo "&lt;/tr&gt;";
  
  }
  }                 
  </code></pre>