Jump to content

Mass value change for cron use


master82

Recommended Posts

I've set up my cron to run my php file every hour, but at the moment that file is blank because I'm unsure how to go about it.

In my database I have 3 fields, [[b]Progress[/b]],[[b]maxprogress[/b]] and [[b]work[/b]].

I need a script that does the following:

update [[b]progress[/b]] by 10% of the [[b]maxprogress[/b]], [i]or 15% increase if [[b]work[/b]] = 1[/i]

ensuring that [[b]progress[/b]] does not exceed [[b]maxprogress[/b]]



Hope that wasn't too complicated to understand - anyone know how I can go about this?
Link to comment
https://forums.phpfreaks.com/topic/13784-mass-value-change-for-cron-use/
Share on other sites

This should work:

[code]<?php

$query = mysql_query( "select * from table" );

while( $row = mysql_fetch_array( $query ) )
{
if( $row[work] == 1 ? $work = 15 : $work = 10 );

$new = ( ( 100 / $row[maxprogress] ) * $work ) + $row[progress];

if( $new > $row[maxprogress] ? $new = $row[maxprogress] : $new = $new );

mysql_query( "update table set progress = '$new' where id = '$row[id]'" );
}

?>[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.