Can anyone provide some assistance.
I am getting information in an array from mysql and then displaying an image based on the information. When a users mouse passes over the image or a click I am trying to pass the id from that to a javascript post function which then writes a views or clicks record.
Unfortunately the javascript is only half working as it takes the last id in the array and uses that instead of the specific id. I am not sure how pass the specific id.
I am not a programmer and have been trying to sort this out without assistance, I have also been searching this and other sites for a solution. Thank you to any assistance provided.
<?php
$result = $sql->query("SELECT * FROM carousel WHERE paper = 'Torch2'");
$rows = array();
while ($row = $result->fetch_assoc()) {
$rows[] = $row;
}
$i = 1;
foreach ($rows as $row):
$item_class = ($i == 1) ? 'active item' : 'item';
echo "<div class='$item_class'>";
echo "<div class='clicks mouseovers'>";
echo "<a href='".$row['link']."' target='_blank'><img src='ads/artwork/".$row['filename1']."' /></a>";
?>
<script>
var id = <?php echo $row['id']; ?>;
$("div.clicks").click(function() {
$.post("includes/clicks_carousel",{id:id});
});
$( "div.mouseovers" ).on( "mouseenter", function() {
$.post("includes/mouseovers_carousel",{id:id});
});
</script>
<?
echo "</div>";
echo '</div>';
$i++;
endforeach;