Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-06-2012, 01:23 AM   PM User | #1
Vernk
Regular Coder

 
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Vernk is an unknown quantity at this point
Update every user with loop?

PHP Code:
<?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 != || $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
Vernk is offline   Reply With Quote
Old 10-06-2012, 03:00 AM   PM User | #2
Fou-Lu
God Emperor


 
Fou-Lu's Avatar
 
Join Date: Sep 2002
Location: Saskatoon, Saskatchewan
Posts: 15,639
Thanks: 4
Thanked 2,448 Times in 2,417 Posts
Fou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to allFou-Lu is a name known to all
No. There is absolutely no reason to update every record in a while loop.
PHP Code:
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.
Fou-Lu is offline   Reply With Quote
Users who have thanked Fou-Lu for this post:
Vernk (10-06-2012)
Old 10-06-2012, 05:05 AM   PM User | #3
Vernk
Regular Coder

 
Join Date: Oct 2011
Posts: 113
Thanks: 9
Thanked 1 Time in 1 Post
Vernk is an unknown quantity at this point
Hey thanks,
It looks like it worked. I knew there was a way to do it in SQL just didn't know how
Vernk is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:38 PM.


Advertisement
Log in to turn off these ads.