Jump to content


Photo

Clear a Field Nightly


  • Please log in to reply
3 replies to this topic

#1 SlimSlyk

SlimSlyk
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 June 2006 - 05:29 PM

Hello,

I have a database table with a structure like this:
id
title
url
total_clicks
today_clicks

Basically, I want to select all of the rows where today_clicks does not equal 0 (To prevent unnecessary load at 00:00 when a server seems most likely to crash anyways), and have it clear today_clicks for all of those rows. I was thinking that a foreach would be needed, but I don't have my PHP book handy and don't really know how to structure one.

Could someone help me out here please?

Thanks!
[a href="http://www.newsfortress.com" target="_blank"]NewsFortress[/a] | Non-Stop News
The latest news articles reviewed and added all day long
[a href="http://www.newsfortress.com/blog" target="_blank"]Command Room[/a] | NewsFortress | News Behind the News
A blog maintained by the operators of NewsFortress

#2 Buyocat

Buyocat
  • Members
  • PipPipPip
  • Advanced Member
  • 267 posts

Posted 22 June 2006 - 06:31 PM

I'm not sure if I understand what you're asking, but let me just attempt an answer. If you want this to be done nightly automatically then you'll need to schedule a cron job to run a PHP script. It cannot be done with PHP alone. If you're just interested in going everynight and running the script through your browser then that would work fine. I run a query like:
UPDATE $tablename SET $changingrow = '0' WHERE $someotherrow = '$somecondition'
I hope you can see the intent behind the query, just swap in your values for mine.
Looking for some easy-to-use tools?  Try these, https://sourceforge....jects/utils-php -- I made them myself.  They're distinct tools which are easy to understand and use.  See some examples uses at http://www.anotherearlymorning.com

#3 SlimSlyk

SlimSlyk
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 June 2006 - 06:51 PM

I know that I will need to run a cron job to do this.

Mostly I guess I am curious to know how I can select rows from the table where today_clicks does _not_ equal 0. From there I should be able to do a where() to update each row.
[a href="http://www.newsfortress.com" target="_blank"]NewsFortress[/a] | Non-Stop News
The latest news articles reviewed and added all day long
[a href="http://www.newsfortress.com/blog" target="_blank"]Command Room[/a] | NewsFortress | News Behind the News
A blog maintained by the operators of NewsFortress

#4 SlimSlyk

SlimSlyk
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 22 June 2006 - 09:16 PM

Nevermind, figured it out.

Thanks!
[a href="http://www.newsfortress.com" target="_blank"]NewsFortress[/a] | Non-Stop News
The latest news articles reviewed and added all day long
[a href="http://www.newsfortress.com/blog" target="_blank"]Command Room[/a] | NewsFortress | News Behind the News
A blog maintained by the operators of NewsFortress




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users