Task -> Update Age
Niki Offline
Junior Member
**
Posts: 29
Joined: Oct 2016
Post: #3
RE: Task -> Update Age
I figured out that it was incorrect table wise as it is not mybb_ it's actually mybbsc_ for my database.

Here is the full code:

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 <?php
/**
* Author: Shinka
* Description: Task that, when ran, automatically adjusts all characters' ages
* based on current age, registration date, and current date.
*/

function task_age($task)
{
global $mybb, $db;

/**
* INCREMENT AMOUNT
* Amount to increment age by.
* Can be integer (e.g. 1) or float (e.g. 0.5).
*/
$INCREMENT = 0.5;

/**
* UPDATE AGE
* Replace "fid18" with the ID of your custom profile field.
* If your age field only allows whole numbers, change "DECIMAL(11, 2)" to "UNSIGNED".
*/
$query = $db->query("
   UPDATE mybbsc_userfields userfields
   SET fid2 = CAST(fid2 as DECIMAL(100, 1)) + {$INCREMENT};
");

add_task_log($task, "The age characters task successfully ran.");
}


I'm also noticing that the regular expression for the profile field will not recognize 0 (as if filled in on the profile as 0 it will not show up, just acts as if it doesn't even exist? which is weird and then also won't update with the task).

Changed "DECIMAL(11, 2)" to "DECIMAL(100, 1)" so that there was more room for numbers before the decimal and only one number after the decimal.

I originally did not want decimals at all, just whole increments and tried to follow the tutorial for that, however when replacing "DECIMAL(100, 1)" with "UNSIGNED" it shows up as another SQL error like that is completely incorrect variable? I'm wondering if maybe this script is just certainly too buggy or incorrect to use?

Example with "DECIMAL(100, 1)" changed to "UNSIGNED" :

PHP Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
 <?php
/**
* Author: Shinka
* Description: Task that, when ran, automatically adjusts all characters' ages
* based on current age, registration date, and current date.
*/

function task_age($task)
{
global $mybb, $db;

/**
* INCREMENT AMOUNT
* Amount to increment age by.
* Can be integer (e.g. 1) or float (e.g. 0.5).
*/
$INCREMENT = 1;

/**
* UPDATE AGE
* Replace "fid18" with the ID of your custom profile field.
* If your age field only allows whole numbers, change "DECIMAL(11, 2)" to "UNSIGNED".
*/
$query = $db->query("
   UPDATE mybbsc_userfields userfields
   SET fid2 = CAST(fid2 as UNSIGNED) + {$INCREMENT};
");

add_task_log($task, "The age characters task successfully ran.");
}

12-26-2017 06:36 AM
Find all posts by this user Quote this message in a reply

« Next Oldest | Next Newest »

Messages In This Thread
Task -> Update Age - Niki - 12-26-2017, 03:40 AM
RE: Task -> Update Age - RateU - 12-26-2017, 03:56 AM
RE: Task -> Update Age - Niki - 12-26-2017 06:36 AM
RE: Task -> Update Age - RateU - 12-29-2017, 01:26 AM

 Standard Tools
Forum Jump: