Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts

    Link to +1 to database

    How can I make it so that when someone clicks on an image on my site that it places a +1 to the DB.?


    kinda like a click tracker.


    Thanks, in advance.

    Slayer.
    Last edited by SlayerACC; 01-18-2013 at 04:58 PM.

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You pass a GET parameter in the url to dictate what item is increased, and then issue an insert or update statement.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #3
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    something like this for the insert command

    PHP Code:
    mysql_query("UPDATE imageadvert SET `hits` = `hits`+1 WHERE image_id = '$image_id'"); 
    How to I work it off the <a href=""> of the click for the image?

    Slayer.

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You add a querystring to the link for whatever name the $image_id has been extracted from. Make sure you filter it through mysql_real_escape_string too.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #5
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    how about if the image is clicked?

    I can not edit the link or pass a value in the link.

    how can you setup something like a passthrough file that will send the link and the id of the ad image.

    Slayer.

  • #6
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    So you cannot change the HTML, but want to change what the HTML does?
    Why can you not change the HTML?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #7
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    228
    Thanks
    45
    Thanked 3 Times in 3 Posts
    how can I get the link to call this funtion??

    PHP Code:
    function countclick($advert_id)
    {
    include (
    'config.php');
    mysql_query("UPDATE adverts SET clicks = clicks + 1 WHERE advert_id = '" $advert_id "'") or die(mysql_error());


    PHP Code:
    $ad="<a href=\"".$row['link']."\" target=\"_blank\" onclick=\"'.countclick($advert_id);.'\" onmouseout=\"window.status=' ';return true;\">".$row['image']."</a><br/>"

  • #8
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    You don't. The first code is PHP which is server side, and the second one is a client side link. The href in that link has to target a PHP script that is capable of calling countclick.
    Perhaps that javascript countclick has some ajax or something that calls the PHP script?
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •