NeoMarine Posted August 2, 2008 Share Posted August 2, 2008 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 https://forums.phpfreaks.com/topic/117786-need-help-with-working-out-a-query/ Share on other sites More sharing options...
fenway Posted August 5, 2008 Share Posted August 5, 2008 Your "where condition" is basically a LEFT JOIN...IS NULL. Link to comment https://forums.phpfreaks.com/topic/117786-need-help-with-working-out-a-query/#findComment-608973 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.