Raised This Month: $ Target: $400
 0% 

How to give everybody in db a one time amount of credits?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
vodka00
Veteran Member
Join Date: Jun 2012
Location: Los Angeles
Old 04-09-2013 , 22:07   How to give everybody in db a one time amount of credits?
Reply With Quote #1

Hello,

If I want to start using "first_connection_credits" "1000" for people that join from now on. Then I would also like to give all the people that were added to the database before this feature. So that it's fair for everyone.

Is there some sql code I can run through my database that will give everyone currently in it a set amount of credits? In this case 1000.

Thanks.
__________________
cw main:

cw speedruns:
vodka00 is offline
eXemplar
Member
Join Date: Feb 2013
Old 04-09-2013 , 22:33   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #2

Something like this:
Code:
update store_users set credits = 1000 where credits < 1000
eXemplar is offline
Arrow768
Veteran Member
Join Date: Nov 2011
Location: Austria
Old 04-10-2013 , 02:34   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #3

I would do it via php:
Create a file named update_users.php in application/controllers
PHP Code:
<?php

if (!defined('BASEPATH'))
    exit(
'No direct script access allowed');

class 
update_users extends CI_Controller {

    function 
__construct() {
        
parent::__construct();
        
$this->load->model('users_model');

        if (!
$this->ion_auth->logged_in() && $this->config->item('storewebpanel_enable_loginsystem') == 1) {
            
redirect('auth/login');
        }
    }

    public function 
index() {
        
$DB_Main $this->load->database("default"TRUE);
        
$query $DB_Main->get("store_users");

        foreach (
$query->result_array() as $row) {
            
$this->users_model->add_credits($row['id'], "1000");
            echo 
"gave user".$row["name"]."1000 credits </br>";
        }
    }

}
Then navigate to index.php/update_users and you should see something like:
Code:
gave userA 1000 credits
gabe userB 1000 credits
Once you have done this every user should have 1000 additional credits
if you want to change the amount of the credits just edit the 1000 to the number of credits you want to give

You could also use the sql mentioned by eXemplar, but then you just set the number of credtis to 1000 for everyone with less then 1000 credtis
__________________

Last edited by Arrow768; 04-10-2013 at 02:36.
Arrow768 is offline
exactprecisions
Member
Join Date: Apr 2013
Old 04-10-2013 , 20:00   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #4

Yea I'm not sure if SQL allows you to store the present value in a variable and them add 1000 and then update, updating it or the same in a SQL query like the first person mentioned, would not add 1000 but instead replace whatever credits were earned already with 1000

It's best to do it with PHP or something similar so you could store the present value for each user in a variable and then add 1000 and store it to a new variable, then "update" it with a sql query with the new variables value
exactprecisions is offline
Arrow768
Veteran Member
Join Date: Nov 2011
Location: Austria
Old 04-11-2013 , 06:50   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #5

Quote:
Originally Posted by exactprecisions View Post
[...]
It's best to do it with PHP or something similar so you could store the present value for each user in a variable and then add 1000 and store it to a new variable, then "update" it with a sql query with the new variables value
And now guess what the code I have posted above does
__________________
Arrow768 is offline
Phault
Junior Member
Join Date: Mar 2013
Old 04-11-2013 , 09:27   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #6

Code:
UPDATE store_users SET credits = credits+1000;
That should do it.

Last edited by Phault; 04-11-2013 at 09:28.
Phault is offline
Arrow768
Veteran Member
Join Date: Nov 2011
Location: Austria
Old 04-11-2013 , 10:16   Re: How to give everybody in db a one time amount of credits?
Reply With Quote #7

Quote:
Originally Posted by Phault View Post
Code:
UPDATE store_users SET credits = credits+1000;
That should do it.
Wow, thats easy.
I never thought that there is such an easy solution
__________________
Arrow768 is offline
Reply



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 -4. The time now is 04:24.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode