samedi 7 novembre 2015

How to improve my if else statement for my additional program function

now I would like to do a simple slave-gaming buy/sell function.

Now my database :T1, My data is:

+----------+------------+------------+-----------+------------+----------+
| uid      | exp        | lvl        | master    | slaveby    |bytime    |
+----------+------------+------------+-----------+------------+----------+
| 1        | 123        | 1          | 10        | 20         |12345     |
| 20       | 456        | 1          | 1         | 0          |12345     |
| 10       | 111        | 2          | 0         | 1          |12222     |
+------------------------------------------------------------------------+

uid is user ID. type int(11)

exp is user experience. type int(11)

lvl is user level. type int(11)

master means now the user is which uid's master. type int(11)

slaveby means now the user is which uid's slave. type int(11)

bytime is the time when user slaveby. type int(11)

In the table data, we can know row 1 was the user 1 was the user 10 master, but also was user 20's slave.

Now my coding run like this.

if ($_GET['mod'] == 'hireSlave'){
        mysql_query("UPDATE ".DB::table('game_goldwar_labour')." SET touid = '".$_GET['touid']."', bytime = '".$_GET[timestamp]."' WHERE uid = '".$_GET[uid]."'");
        mysql_query("UPDATE ".DB::table('game_goldwar_labour')." SET byuid = '".$_GET[uid]."', bytime = '".$_GET[timestamp]."' WHERE uid = '".$_GET['touid']."'");
};

But this coding the user only can be 1 user's master only.

I would like to change when user lvl 2, can be 2 slave's master, lvl3, can be 3 slave's master, maximun 5 slave, and also the bytime need to separate. Because I set when the bytime is reach the maximun time, the slave user will auto runaway. If this slave is in the second slot, will update the slave second slot as 0 (normally is user id of the slave, but because already runaway, so set to 0), after that, when the master hire slave when the slot is available.

slot available based on level and the slot was 0.

And also when user lvl1, cannot get 2 slave.

If I use if/else statement, will be a huge script.

So how to improve this? thank you.

Aucun commentaire:

Enregistrer un commentaire