dennismonsewicz Posted September 16, 2009 Share Posted September 16, 2009 Ok... I have this code: $this->load->database(); $affiliateId = $this->session->userdata('affiliateId'); $hashQuery = $this->db->get('paypal_payment_info'); foreach($hashQuery->result() as $hash) { $code[] = $hash->custom; } for($i = 0; $i < $hashQuery->num_rows(); $i++) { $count = explode("|", $code[$i]); $partOne = $count[0]; if($partOne == $affiliateId) { $partTwo = $count[1]; $partThree = $count[2]; $hash = $partOne . "|" . $partTwo . "|" . $partThree; $q = $this->db->query("SELECT custom, mc_gross, mc_fee, txn_id FROM paypal_payment_info WHERE custom = '$hash'"); $num = $q->num_rows(); if(strstr($hash,'Choose_Me_(Album)')) { $album_sales = ($q->num_rows() * 10) * .05; } else { $album_sales = '0'; } } else { $data['no_earnings_total'] = "You currently have no sales."; $album_sales = 'You have no Album Sales'; $num = 0; } } $data['album_sales'] = $album_sales; if($num > 0) { foreach($q->result() as $row) { $mc_gross = $row->mc_gross; $mc_fee = $row->mc_fee; $txn_id[] = $row->txn_id; } $total_earnings = ($mc_gross * $q->num_rows()) - ($mc_fee * $q->num_rows()); if($total_earnings != 0) { $data['total_earnings'] = $total_earnings; } else { $data['total_earnings'] = '0.00'; } } I think I have my for loops all screwed up somewhere... basically the code above hits a DB and grabs ALL of the rows from paypal_payment_info and then I grab ALL of the custom values and place them into an array... I iterate through that array and the explode the the string to pull out the first item in that array (the custom field holds a piped code that I need to pull out the first value in the first piped section) I then try to see if the $partOne matches the sessioned affiliateId and if so then follow the rest of the code, but for some reason the $partOne is having problems matching the affiliateId... Any ideas here? Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/ Share on other sites More sharing options...
dennismonsewicz Posted September 16, 2009 Author Share Posted September 16, 2009 bump Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/#findComment-919327 Share on other sites More sharing options...
Zane Posted September 16, 2009 Share Posted September 16, 2009 Ok... I think I have my for loops all screwed up somewhere... [....] Any ideas here? which for loop(s).? why is it screwed up? where exactly is the problem...exactly? Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/#findComment-919335 Share on other sites More sharing options...
dennismonsewicz Posted September 16, 2009 Author Share Posted September 16, 2009 If I print_r($code) I get all of the items in the array as they should... if I do a print_r($partOne) I get all of the items in the array as they should... But for some reason I can't get $partOne and $AffiliateId to match... it disregards the items in the if and then does the else on this if/else statement... That is the first part... I am having some other problems, but I need to get this one addressed before I can really move on to another section. Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/#findComment-919338 Share on other sites More sharing options...
Zane Posted September 16, 2009 Share Posted September 16, 2009 and wHy would $partOne == $affiliateId in the first. What are these variables? What is this code? In order to get some decent thorough help on this you're going to have to explain what these variables are and why they aren't doing what they're doing. You say $code works fine and does a damn good print_r job.. Well .. what's in it? What is it? What do you want these variables to hold. ...lots of whats. In other words...Only you know what the variables need to hold for them to pass these....if statements you've crafted.. we haven't the slightest clue. You've dumped you're code here from some class I've never seen..in hopes of a miracle answer. It won't happen unless you explain yourself better. No offense. don't freak out or anything..just bein straight with ya. Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/#findComment-919340 Share on other sites More sharing options...
dennismonsewicz Posted September 16, 2009 Author Share Posted September 16, 2009 @zanus: My apologies for not being thorough in my explanation of everything involved with my code... I will try to explain everything here $this->load->database(); $affiliateId = $this->session->userdata('affiliateId'); $hashQuery = $this->db->get('paypal_payment_info'); foreach($hashQuery->result() as $hash) { $code[] = $hash->custom; } for($i = 0; $i < $hashQuery->num_rows(); $i++) { $count = explode("|", $code[$i]); $partOne = $count[0]; if($partOne == $affiliateId) { $partTwo = $count[1]; $partThree = $count[2]; $hash = $partOne . "|" . $partTwo . "|" . $partThree; $q = $this->db->query("SELECT custom, mc_gross, mc_fee, txn_id FROM paypal_payment_info WHERE custom = '$hash'"); $num = $q->num_rows(); if(strstr($hash,'Choose_Me_(Album)')) { $album_sales = ($q->num_rows() * 10) * .05; } else { $album_sales = '0'; } } else { $data['no_earnings_total'] = "You currently have no sales."; $album_sales = 'You have no Album Sales'; $num = 0; } } $data['album_sales'] = $album_sales; if($num > 0) { foreach($q->result() as $row) { $mc_gross = $row->mc_gross; $mc_fee = $row->mc_fee; $txn_id[] = $row->txn_id; } $total_earnings = ($mc_gross * $q->num_rows()) - ($mc_fee * $q->num_rows()); if($total_earnings != 0) { $data['total_earnings'] = $total_earnings; } else { $data['total_earnings'] = '0.00'; } } The PHP framework I am using is CodeIgniter. $this->load->database(); $affiliateId = $this->session->userdata('affiliateId'); $hashQuery = $this->db->get('paypal_payment_info'); foreach($hashQuery->result() as $hash) { $code[] = $hash->custom; } for($i = 0; $i < $hashQuery->num_rows(); $i++) { $count = explode("|", $code[$i]); $partOne = $count[0]; if($partOne == $affiliateId) { $partTwo = $count[1]; $partThree = $count[2]; $hash = $partOne . "|" . $partTwo . "|" . $partThree; Explanation: $affiliateId is a variable that is grabbing the session of affiliateId... this is set when a user logs into the system. $hashQuery basically just gets ALL records from the paypal_payment_info The foreach statement loops through all of the records and writes the column of `custom` into an array called $code[]. I then loop through each of the values in the $code[] array and explode (split apart) each value into separate parts... now the `custom` column in the table is where the original guy on this project saved different values into a piped value... example: 5|Choose_Me_(Album)|8803632a5d117faf7f50a8ae769a0eb8 breakdown of example above: 5 = affiliateId Choose_Me_(Album) = The purchased item 8803632a5d117faf7f50a8ae769a0eb8 = This is a hash value that I am not 100% sure on why is needed (I was not given direction on this item) but I am not overly concerned with this item at the moment. Ok... so the variable of $partOne is the first part of this piped value that is in the `custom` column... I am trying to match $partOne with the sessioned $affiliateId Zanus, again my apologies for not being as thorough as I should have been... does my above breakdown help any? One more thing... print_r($code) prints this out: Array ( [0] => 2|Choose_Me_(Single)|9787d7a24b2af9da8bc026acd1e38f0a [1] => 2|Choose_Me_(Album)|8803632a5d117faf7f50a8ae769a0eb8 [2] => 5|Choose_Me_(Album)|8803632a5d117faf7f50a8ae769a0eb8 ) and print_r($partOne) prints this out: 2 2 5 Each value in the $partOne var holds the first part of the exploded $code var and these again are the affiliate Ids Hope this clears this up bud Quote Link to comment https://forums.phpfreaks.com/topic/174414-for-loop-help/#findComment-919539 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.