php code error, plz help!!!

Discussion in 'PHP' started by onlinearnings, Dec 30, 2011.

  1. #1
    I got an error like this:

    Warning: in_array() [function.in-array]: Wrong datatype for second argument in /home/manzoon/public_html/wp-content/themes/clipper/includes/theme-voting.php on line 135

    The php code is:

    
    	// calculate the total successful percentage and round to remove all decimals	
    	if($row->votestotal>0) $votes_percent = round($row->votesup / $row->votestotal * 100);
        else $votes_percent = 100;
    	
    	// update/create meta keys on the post so it's easy to call from the loop
    	update_post_meta($post_id, $app_abbr. '_votes_up', $row->votesup);
    	update_post_meta($post_id, $app_abbr. '_votes_down', $row->votesdown);
    	update_post_meta($post_id, $app_abbr. '_votes_percent', $votes_percent);
    	
    	echo $votes_percent . '%'; // send back the % result so we can update the coupon % value in real-time
    	die; // so it doesn't return an extra zero	
    }
    
    
    // check if the visitor or user has already voted
    // called within the coupon loop
    function clpr_vote_check($post_id, $the_trans) {
    	
    	// see if the post id exists in the array meaning they already voted
    [COLOR="#FF0000"]	if (in_array($post_id, $the_trans))[/COLOR]
    		return true; 
    	else 
    		return false; 		
    }
    
    Code (markup):
    The red line is the line 135 which marked as an error, how to fix it?

    Thanks for your help!

    You also can check the problem on my site couponbanks.com

    In the rating area, thanks for everyone.
     
    Solved! View solution.
    onlinearnings, Dec 30, 2011 IP
  2. #2
    Change:

    
    function clpr_vote_check($post_id, $the_trans) {
    
    PHP:
    To:

    
    function clpr_vote_check($post_id, $the_trans) {
        if (!isset($post_id) || !is_array($the_trans)) { 
            return false; 
        }
    
    PHP:
     
    ThePHPMaster, Dec 30, 2011 IP
  3. AlexanderZ

    AlexanderZ Member

    Messages:
    28
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    48
    #3
    You need to post the code for how you are calling that function. Depending on what is passed into it, the code above might not do what the function description says.
     
    AlexanderZ, Jan 3, 2012 IP
  4. misbah

    misbah Active Member

    Messages:
    265
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    68
    #4
    function clpr_vote_check($post_id, $the_trans) {
    	// see if if $the_trans is array
    	if(is_array($the_trans) {
    		// see if the post id exists in the array meaning they already voted
    		if (in_array($post_id, $the_trans))
    			return true;
    		return false;
    	}
    }
    PHP:
     
    misbah, Jan 5, 2012 IP