0

on my website: http://gracebook.pl/ I added fancybox so that users can display larger versions of images (see magnifier icon near each image).

Under every photo there's also information how many times it was clicked. But this feature works only when user clicks on a photo and open it in new page.

I'm trying to figure out if there's a way to count clicks with fancybox so that image gain +1 view when user clicks on magnifier and launching fancybox.

Any clues?

I think I should somehow add a function like this:

 function myCall() {
  var request = $.ajax({
   url: "PHP FILE URL",
   type: "GET",
   data: {n : '__hash__'},
   dataType: "html"
  });

And then query database with php:

mysql_connect("IP", "USER", "PASS") or die(mysql_error());
mysql_select_db("DB NAME") or die(mysql_error());

mysql_query("UPDATE `TABLE` SET `Views` = `Views` +1 WHERE `Hash` = 'SOMETHING'"); 

But I have no idea how to do this :)

I would be grateful for any clues.

I'm using Version: 1.3.4 (11/11/2010).

Tompo
  • 15
  • 6

1 Answers1

0

You can easily count clicked like:

var click = 0;
function myCall() {
    click++;
    var request = $.ajax({
       url: "PHP FILE URL",
       type: "GET",
       data: {n : '__hash__',click : click},
       dataType: "html"
    });
}

HTML

<div class="callFancybox" onclick="myCall()"></div>
Lewis
  • 14,132
  • 12
  • 66
  • 87
  • Thanks, but I tried to do this this way and in my case there's to many issues with html and onclick. For example when I try to identify image by hash, function myCall shows correct hash but php doesn't. Thats why I'm trying to figure out how to add this function to jquery.fancybox.js file (with afterload/onComplete etc.) and call php from there, after certain image has been loaded and I can track it's hash or ID. Sorry for my English :) – Tompo May 18 '14 at 20:00
  • I don't really get your problem. Why doesn't PHP receive the correct hash? What did PHP show? – Lewis May 18 '14 at 20:09
  • myCall function shows correct hash/ID but PHP always shows hash or ID of the last image on the page. – Tompo May 18 '14 at 20:16
  • May be something's wrong with your JS code. PHP always receives exactly what AJAX sent. – Lewis May 18 '14 at 20:29
  • I think that problem lies in html. I have 20 images on page, all of them with the use of the same html file (thumb.html). Like this: __alt__. So is the magnifier icon: . Maybe that's why onclick always passes the last hash (it's the same image and link repeated 20 Times). – Tompo May 18 '14 at 20:45
  • The other problem is that for some reason onclick collides with a href="fancyUrl" and fancybox stops to work as it should. I tried this solution: http://stackoverflow.com/questions/1346043/html-anchor-link-href-and-onclick-both and other, but nothing helps. Thats why I've decided to leave html alone and try to call PHP directly from jquery.fancybox.js. 1) User clicks on magnifier icon, 2) fancybox triggers lightbox image, 3) After the image is loaded jquery.fancybox.js triggers PHP and +1 view is added to the image with specific hash or ID. – Tompo May 18 '14 at 21:00