Jump to content

Need help with working out a query


NeoMarine

Recommended Posts

I have two tables, one called tbl_views and another called tbl_pages.

 

In tbl_views there are 4 fields, "ID", "IPAddress", "TodaysDate" and "PageID". In tbl_pages I have a field called "TotalViews" and "ID".

 

When a person visits a page (which has a specific PageID), I record into tbl_views a new row with their IPAddress. If a record already exists on that day then I do not add the record to tbl_views since I already recorded them visiting that specific page.

 

What I need is a query that (before the previous update query) updates tbl_pages "Total Views" to +1, but only if the IPAddress of the visitor is not yet recorded into tbl_views.

 

So, I think it should be something like:

 

UPDATE tbl_pages SET TotalViews=TotalViews+1 WHERE "no IP address exists in tbl_views for tbl_views.PageID which equals to tbl_pages.ID"

 

Can you help me with this query? I can't quite figure it out.... my brain is fried!

 

edit:

 

Also, at the end of each day I need to clear the tbl_views table... I don't want to use a cron job so I was thinking maybe each time the page loads, it can check the date and clear it if its a new day, or every 2 days or something? Do you think that would be efficient? I have trouble understanding "cron jobs"

Link to comment
Share on other sites

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.