Web Analytics Made Easy -
StatCounter Help with PHP code for Game Sharing site - CodingForum

Announcement

Collapse
No announcement yet.

Help with PHP code for Game Sharing site

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with PHP code for Game Sharing site

    I have a website where users list games they have in a "have list" and games they want in a "wish list". there is a swap matcher function where the user selects this option and It checks their "wish" and "have" lists with other users "wish" and "have" lists and displays potential swaps.

    The function is working but it is also matching "wish" lists up with "wish" lists which is causing confusion to the users and causing trade requests that can not be for filled.

    I tried looking at the code and can not see where it is going wrong

    Can someone have a quick look and see if you can see where have went wrong?

    Thanks for your assitance.


    PHP Code:
    //SWAPPER MATCHER GAME
    function aa_swap_matcher($user_id){
        
            
    $query1 $this->db->query("SELECT `game_id`,`plat_id`,`wishorhave` FROM (`user_games`) WHERE `user_id` = '$user_id' ");
            
    $wish_game_ids=$query1->result_array();
            
    $game_ids = array();
            if(
    $wish_game_ids){
                
    $i=0;
                foreach(
    $wish_game_ids as $wish_game_id){
                    
    $query2 $this->db->query("SELECT * FROM (`user_games`) WHERE `game_id` = '$wish_game_id[game_id]' AND `plat_id`='$wish_game_id[plat_id]' AND `user_id` != $user_id");
                    
    $have_game_ids=$query2->result_array();
                        if(
    $have_game_ids){
                            
    $game_ids[$i]=$have_game_ids;
                        }
                    
    $i++;
                    }
    //end have_game_ids
                    
    assign("all_game_ids",$game_ids);

                    } else {
                          
    assign("all_game_ids"FALSE);
                    }
            
                
            
    $this->mysmarty->register_function("gameinfo""do_game_info");
            
    $this->mysmarty->register_function("username""do_getUserName");        
            
    $this->mysmarty->register_function("condition""do_getGameCondition");
            
    $this->mysmarty->register_function("plat_type""do_plat_type");
            
    $this->mysmarty->register_function("from_wish_have""do_from_wish_have");
                    
            
    $viewFiles = array('contentView' => 'templates' DS 'swap_matcher.tpl');
            
    showPage($viewFiles,'PAGE');
        }

    //
    //
    //


    function swap_matcher($user_id FALSE){
        
        
    $user_id=$this->session->userdata('user_id');

        if(
    $user_id){

        
    $matches = array();
    //    $matches[$i]['user_one'] = array();
    //    $matches[$i]['user_two'] = array();
        
    $game_list get_users_game_list($user_id);

        foreach (
    $game_list as $game) {
                if (
    $game['wishorhave'] == 'Wish'){
                    
    $matched_user matched_game_list($game['game_id'], 'Have'$user_id1); 
                    foreach (
    $matched_user as $user_2){
                        
    $user_2_wish_list get_users_game_list($user_2['user_id'], 'wish');
                        if (
    $user_2_wish_list){
                            foreach (
    $user_2_wish_list as $user_2_wish_list_game){
                                if (
    is_in_users_game_list($user_id$user_2_wish_list_game['game_id'], 'Have'$game_list)){
                                    
    $matches[$game['game_id'].",".$game['plat_id']][] = $user_2_wish_list_game;
                                }
                        }
                    }
                }
            }
        }
        
    // swap match array
        //print_r($matches);
        
        
    if (empty($matches)){
        
    assign('all_game_ids',FALSE);                
        } else {
            
    assign('all_game_ids',$matches);        
        }
        
        
    $this->mysmarty->register_function("explode""do_explode");            
        
    $this->mysmarty->register_function("usergame""do_get_user_game");
        
    $this->mysmarty->register_function("gameinfo""do_game_info");
        
    $this->mysmarty->register_function("username""do_getUserName");        
        
    $this->mysmarty->register_function("condition""do_getGameCondition");
        
    $this->mysmarty->register_function("plat_type""do_plat_type");
        
    $this->mysmarty->register_function("from_wish_have""do_from_wish_have");        
        
    $viewFiles = array('contentView' => 'templates' DS 'swap_matcher.tpl');
        
    showPage($viewFiles,'PAGE');

        } else {
            
    redirect('authorization/login');
        }

    Last edited by juln; Apr 9, 2009, 11:36 AM.

  • #2
    It probably has something to do with the fact that your code is comparing wish lists to wish lists.

    Comment

    Working...
    X