eg: podcast001.mp3 plays: 12
I have set up a column in a mysql database for each podcast called 'counter'.
I then tried to make a php-javascript hybrid code with functions on onClick that went into and added one to the counter column of the appropriate row in the mysql database. This failed miserably. Turns out you cannot mix these things, one being client based, the other browser based.
Is this the best way to approach the problem? Am I missing something really obvious? Is it possible to use awstats somehow? Is there a sneaky way of getting php code to act like java's onClick? I searched around for tutorials and examples but I haven't come across anything that helps.
The site is www.hockeyrant.com if that helps.
Any help on an idea of how to approach this would be greatly appreciated.
Here is the function that browser's really don't like:
Expand|Select|Wrap|Line Numbers
- <script type="text/javascript">
- <!--
- function addCounter() {
- <?php
- [connect to appropriate database with appropriate passwords]
- $query = "select counter from hockeyrant where (id='$id') limit 1";
- $result = mysql_query($query) or die('Query failed: ' . mysql_error());
- $numrows=mysql_numrows($result);
- if ($numrows == 0) {
- exit;
- }
- else {
- $counter = mysql_result($result, 0, counter);
- $counter = $counter + 1;
- $query3="update hockeyrant set counter = '$counter' where id = $id";
- $result3=mysql_query($query3) or die('Query failed: ' . mysql_error());
- exit;
- }
- mysql_free_result($result);
- mysql_close($db);
- ?>
- }
- //-->
- </script>