| Check database value cron/php and change if true change database value with cron php |
zorro

msg:4190190 | 1:42 pm on Aug 21, 2010 (gmt 0) | Is it possible to check a mysql database value once a day with a cron job and using php change it if true? Basically when someone enters an item into the database it is assigned a 'type' value of '1' (items are usually listed for 12 months). The user of the item may make it 'Featured' at any time for 1 month or 3 months, which assigns it a 'type' value of '2'. Once the 1 or 3 month 'Featured' is over I want to convert the 'type' value back to 1 in the database but at the moment it is staying at '2'. I would like to run a cron job - once a day to check that if the 'Featured date end' is less than today - change 'type' value back to '1'. Would I get the cron job to run some kind of php script to change the value? Any help appreciated!
|
rocknbil

msg:4190262 | 4:49 pm on Aug 21, 2010 (gmt 0) | Well, I'd do it in perl, but yeah, you should be able to set up a daily cron for that. :-) First disable your 12 month ones. | Basically when someone enters an item into the database it is assigned a 'type' value of '1' (items are usually listed for 12 months). |
| update table set type=0 where approved=1 and date_add(posted_date, interval 12 month) <= curdate(); in the same script, now run the second command. | I would like to run a cron job - once a day to check that if the 'Featured date end' is less than today - change 'type' value back to '1'. |
| update table set type=1 where approved=1 and featured_date_end <= curdate();
|
Frank_Rizzo

msg:4190265 | 4:56 pm on Aug 21, 2010 (gmt 0) | Even easier would be a cron job running a mysql script: #dailyupdate.sh mysql --user=yourdatabaseuser --password=yourpassword <dailyupdate.sql create dailyupdate.sql from rocknbill's example above. #dailyupdate.sql update table set type=1 where approved=1 and featured_date_end <= curdate(); Now set up a cron job to run dailyupdate.sh just before / after midnight or so.
|
zorro

msg:4190376 | 12:09 am on Aug 22, 2010 (gmt 0) | cheers guys
|
|
|