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 8246347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T22:28:38+00:00 2026-06-07T22:28:38+00:00

I am writing PHP script, which will store mouse position over the page with

  • 0

I am writing PHP script, which will store mouse position over the page with a timestamp. It will be used for generating simple heatmap.
I have MySQL database of X & Y coordinates and I thought, that I would do an array, which I would use for adding counts of appearances of the cursor over specific pixel.
It would work like this:
I read data from the database saying for example four recordings (x/y) 10/9,8/7,2/10,10/9
I would put 1 on each of the coordinates in the array, the last point would already in the array, so it would put 2 on x=10/y=9, as total count of mouse being over that pixel.

How should I make the array and how to read it?

  • 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-07T22:28:40+00:00Added an answer on June 7, 2026 at 10:28 pm

    First, you need to create an empty matrix, where the entire grid is defined and populated with zeros:

    $width = 10;
    $height = 10;
    
    $matrix = array_fill(1, $height, array_fill(1, $width, 0));
    

    Now you simply iterate over your MySQL results and increment each associated point every time you hit it. In this example I assume your x and y columns are just called x and y.

    while ($row = mysql_fetch_assoc($queryResult)) {
      $matrix[$row['y']][$row['x']]++;
    }
    

    Now if you want to get the number of hits for the point where e.g. x = 1, y = 8, you simply do:

    $hits = $matrix[8][1];
    

    You can swap the levels round so x is on the outer level so they can be referenced as $matrix[$x][$y] instead of $matrix[$y][$x] if you wish, but I personally feel it makes more sense if the array is structured as rows of columns (ys of xs) like a database table.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am writing a php script which will run through cron . Its task
I'm writing a php script which will enable people to change the theme of
I am writing a bunch of PHP classes which will be used to create
I am writing a PHP script (which also uses linux bash commands) which will
I am writing a PHP script for a client which will be installed on
I am writing a PHP script that will send via a cron an email
I'm currently writing a little commercial PHP Script which would be a VPN (PPTP)
I'm writing a php script that will fetch data from a given URL and
I am writing a script in php, which is quite similar to a shopping
I am writing php code which will work under *nix systems. I need to

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.