Jump to content


Photo

Mass value change for cron use


  • Please log in to reply
2 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 05 July 2006 - 08:25 PM

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, [Progress],[maxprogress] and [work].

I need a script that does the following:

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

ensuring that [progress] does not exceed [maxprogress]



Hope that wasn't too complicated to understand - anyone know how I can go about this?

#2 mrwhale

mrwhale
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts

Posted 06 July 2006 - 03:25 AM

This should work:

<?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]'" );
}

?>


#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 06 July 2006 - 08:47 AM

Thank you - I'll give it a try now :-)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users