public function memberGames($mid, $gid, $serverIdValue) { $modelMemberGames = new MemberGames(); $MemberGames = $modelMemberGames->findByAttributes(array('mid' => $mid)); if ($MemberGames) { $MemberGamesArr = array(); for ($i = 1; $i <= 6; $i++) { $gidNum = 'gid' . $i; if ($MemberGames->{$gidNum} !== null) { $MemberGamesArr[$i] = unserialize($MemberGames->{$gidNum}); } else { continue; } } foreach ($MemberGamesArr as $vo) { if ($vo['gid'] == $gid && $vo['serveridvalue'] == $serverIdValue) { return $vo; } } if ($MemberGames->gnum >= 6) { $gidTest = serialize(array('gid' => $gid, 'serveridvalue' => $serverIdValue)); $modelMemberGames->updateAll(array('gnum' => '1', 'gid1' => $gidTest), "mid={$mid}"); //echo 6; return true; } else { $gnum = $MemberGames->gnum + 1; $prefixgId = 'gid' . $gnum; $gidTest = serialize(array('gid' => $gid, 'serveridvalue' => $serverIdValue)); $modelMemberGames->updateAll(array('gnum' => $gnum, $prefixgId => $gidTest), "mid={$mid}"); //echo $gnum; return true; } } else { $modelMemberGames->mid = $mid; $modelMemberGames->gnum = 1; $modelMemberGames->gid1 = serialize(array('gid' => $gid, 'serveridvalue' => $serverIdValue)); $modelMemberGames->save(false); } }