Jump to content

Recommended Posts

I have a little project going that's more of a programming exercise than anything.  It keeps track of outbound links from a site and I'm trying build a statistics page.

 

I have two tables. One stores information about web sites and one records the agent, IP, etc.  They look like this:

 

-- sites table --
siteID siteName
  1      test1.com
  2      test2.com
  3      test3.com

-- hits table --
siteID hitAgent
  3      firefox
  3      safari
  2      firefox
  3      safari
  3      firefox

 

I want the report to look like this:

test3.com 4

test2.com 1

test1.com 0

 

I've been looking through the mySQL documentation (gasp!) but I got to admit there's a lot of concepts that I'm missing which makes the going kind of rough.

 

I'm using PHP 4.4.1  and MySQL version  4.1.21-standard.

 

Any advice or a good tutorial?

Three things that "it's doing": joining the tables based upon the FK relationship (siteID), aggregating all matching rows based on siteID for the count, and using left join instead of inner join so that sites with no hits show up with count=0, and are not excluded because of no matching hit rows.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.