...

View Full Version : Update every user with loop?



Vernk
10-06-2012, 01:23 AM
<?php
require "config.php";
$query = mysql_query("SELECT plan, timeleft FROM userinfo");
while ($qrow = mysql_fetch_array($query)) {
$plan = $qrow['plan'];
$timeleft = $qrow['timeleft'];
if ($plan != 0) {
if ($timeleft != 0 || $plan != 123456789) {
mysql_query("UPDATE userinfo SET timeleft = timeleft - 1");
}
}
}


?>
I am trying to do this but instead of minus 1 it is minus 3 on all colums and sometimes -45 and it's doing it to every user even if plan is 0 and time is 0
This is suppose to be an auto cron

Fou-Lu
10-06-2012, 03:00 AM
No. There is absolutely no reason to update every record in a while loop.


mysql_query("UPDATE userinfo SET timeleft = timeleft - 1 WHERE timeleft > 0 AND plan NOT IN (0, 123456789)");

Just because you have controlled a variable in PHP doesn't mean that it will be controlled in SQL. You must provide it with a criteria or it is ALL records.

Vernk
10-06-2012, 05:05 AM
Hey thanks,
It looks like it worked. I knew there was a way to do it in SQL just didn't know how



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum