Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    Regular Coder
    Join Date
    Feb 2005
    Posts
    663
    Thanks
    5
    Thanked 14 Times in 14 Posts

    function variable help

    I'm trying to pass a variable into a function, yet I keep getting an undefined index error, and unsure what could be wrong?

    I'm adding in the first variable at the moment, but it should eventually include the points, kills, wins, and games_played. Yet, just adding the first variable is giving me an error.

    snippet...
    Code:
    while ($rank = mysql_fetch_assoc($result2))
    	{		
    		if($rank['variable'] == 'cust_points'){$row['points'] = $rank['value'];}
    		if($rank['variable'] == 'cust_players'){$row['kills'] = $rank['value'];}
    		if($rank['variable'] == 'cust_win'){$row['wins'] = $rank['value'];}
    		if($rank['variable'] == 'cust_gamesp'){$row['games_played'] = $rank['value'];}	
    		
    		//Get Ranking based on formula
    		$row['ranking'] = rank_formula($row['points']);
    	}
    
    //The function
    function rank_formula($points){
    
    // Ranking code here	
    	return $rank;
    
    }

  • #2
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Code:
    $row['points'] = (($rank['variable'] == 'cust_points') ? $rank['value'] : false);
    $row['kills'] = (($rank['variable'] == 'cust_players') ? $rank['value'] : false);
    $row['wins'] = (($rank['variable'] == 'cust_win') ? $rank['value'] : false);
    $row['games_played'] = (($rank['variable'] == 'cust_gamesp') ? $rank['value'] : false);

    Post your full error code and code up if that makes no difference.
    Last edited by MattF; 03-27-2010 at 09:22 PM. Reason: Typo.

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Posts
    136
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Are you actually calling the function before it exists or is that just how you have pasted the snippets?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •