Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8561701
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:33:39+00:00 2026-06-11T16:33:39+00:00

I wonder how could I modify this existing code in order to track image/banner

  • 0

I wonder how could I modify this existing code in order to track image/banner clicks/views? Is this even possible with just PHP or do you need to use jQuery (ajax)?

I have bannerClicks and bannerViews inside tblbanners in my MYSQL table.

This is the code to generate image/banner:

    $query91 = 'SELECT * FROM tblbanners WHERE tblbanners.bannerStatus!=\'1\'';
    $result91 = full_query ($query91);

    $bannerCounter = 1;
    while ($data91 = mysql_fetch_array ($result91))
    {

        $ID = $data91['ID'];
        $bannerName = $data91['bannerName'];
        $bannerLocation = $data91['bannerLocation'];
        $bannerUrl = $data91['bannerUrl'];      

        $bannerCode[$bannerCounter] = '<a id="' . $ID . '" class="banner-url" href="' . $bannerUrl . '" target="_blank"><img alt="' . $bannerName . '" src="banners/' . $bannerLocation . '" width="100px" height="200px" /></a>';
        $bannerCounter++;
    }

    $bannerAdTotals = $bannerCounter - 1;

    if($bannerAdTotals > 1)
    {
       mt_srand((double)microtime() * 1234567);
       $bannerPicked = mt_rand(1, $bannerAdTotals);
    }
    else
    {
       $bannerPicked = 1;
    }

    $bannerAd = $bannerCode[$bannerPicked];

    print $bannerAd;
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T16:33:40+00:00Added an answer on June 11, 2026 at 4:33 pm

    You can either use JavaScript, or intercept clicks. To intercept clicks, presuming you store the banner URL in the database, you can just set up a PHP script to intercept the click, track the click, and then redirect. Something as simple as:

    <?php
    
    $sql = "SELECT `url` FROM `banners` WHERE `id` = :banner_id LIMIT 1";
    $stmt = $db->prepare($sql);
    $stmt->bindParam(':banner_id', $_GET['id'], PDO::PARAM_INT);
    $stmt->execute();
    $banner = $stmt->fetchObject();
    
    $sql = "INSERT INTO `clicks` (`banner_id`) VALUES (1)";
    $res = $db->exec($sql);
    
    header('Location: ' . $banner->url);
    

    Obviously you’ll need to instantiate your database connection/object, change any database table and column names, and any validation.

    With this approach, when you display your banner you then do this instead when selecting a banner from your database:

    <a href="track_click.php?id=<?php echo $banner->id; ?>">
      <img src="<?php echo $banner->img; ?>" alt="<?php echo $banner->alt; ?>" />
    </a>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm starting to wonder if this is even possible. I've searched for solutions on
I wonder whether someone could help me please. I'm using Image Uploader from Aurigma,
I wonder how could is possible to make custom shape key on android keyboard.
wonder if I could get some advice on the best way to solve this
Wonder if anyone could shed some light on this http://jsfiddle.net/orbitalmedia/ZrxBb/7/ Basically I'm trying to
wonder if someone could help me with a little problem. I have session values
I wonder if someone could help me figure out how to parse a string
I wonder if you could help me with something I've been thinking about. Say
I wonder if someone could be kind enough to explain the function.prototype thingie (thingie!!??)
i wonder how i could store a xml structure in a persistence layer. cause

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.