how to upgrade designation in php data -


i working mlm company's site hv design upgrade status of member 1 step higher after adding 5 members every member has upgrade upper level.i have code dont know how call function

here code:-

function checkandupgradedesignation($username,$des)     {     if($des=='crown')     return;     $q="select introducer_id members user_id='$username'";     $rs=mysql_query($q);     $r=mysql_fetch_array($rs);     $id=$r['introducer_id'];     $q="select count(*) total members introducer_id='$id' , designation='$des'";         $rs1=mysql_query($q);     $r1=mysql_fetch_array($rs1);     $t=$r1['total'];     if($t==5)     {     if($des=="vip")        $des1="journey";        else         if($des=="journey")        $des1="executive";        else         if($des=="executive")        $des1="dreamflight";        else         if($des=="dreamflight")        $des1="safari";        else         if($des=="safari")        $des1="goldrace";        else         if($des=="goldrace")        $des1="royalrace";        else         if($des=="royalrace")        $des1="aashiyana";        else         if($des=="aashiyana")        $des1="crown";        $q="update members set designation='$des1' user_id='$id'";        mysql_query($q);        checkandupgradedesignation($id,$des1);        } } 

pls check code looks right or need change...............if u hv question ask me

you call function this: checkandupgradedesignation('1', 'goldrace');

also might rename function parameter $username $userid, because sql uses user_id.

please escape values inserted sql statment avoid injections.

maybe refactor function 3 functions:

  1. fetchdesignation($user_id) - returns designation user_id
  2. raisedesignation($des) - logic part level , returns new level or false
  3. updatedesignation($user_id, $des) - inserts new level db

this suggestions bit more flexible, depends on use case. allows testing logic raisedesignation() in seperate unit-test, without touching db. fetching designation user_id seperate.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -