BizLab Posted September 11, 2010 Share Posted September 11, 2010 Here is something i dreamt up, i know there is a way for this to work, but i'm not having any great ideas at this point. I want to be able to auto increment through the $_POST[] array data sent from a PayPal IPN. Sample return data looks like item_number1=val item_name1=val so on and so forth. The idea is: While there are $_POST item_numbers, do something with it. The loop continues until there are no more item_numbers. I don't want to use the static methods eg: explicitly defining item_number1, item_number2, ect. This is what i thought would work, but keeps failing -> the script doesn't enter the first condition: $x = 1; // set the initial item number while(isset($_POST['item_number$x'])){ $qty = $_POST['quantity$x']; while($qty > 0){ // step through each item response result, setting each item to paid $package_id = $_POST['item_number$x']; update_paid_status($transaction_id, $package_id); $qty--; } $x++; } Any Ideas? Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/ Share on other sites More sharing options...
BizLab Posted September 11, 2010 Author Share Posted September 11, 2010 Testing shows that the problem is with the $_POST['item_number$x'] more specifically the "$x" variable being stuck in there, but i don't know of another way to iterate through Paypal's slick POST variables... That line was intended to be displayed as: $_POST['item_number1'] $_POST['item_number2'] $_POST['item_number3'] Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110017 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 I am not sure but is the way the dollar-sign with the [] is the way to do it? i have never seen that so i am not sure : ) I am afraid that i know nothing about paypal variables, but if your fetching array results why dont you use the For each loop? If i am correct using the while loop is possible to for running through them but you need list(). Not sure though but it's worth a try. If you could maybe give more code i could come up with something : ) lol May I ask how PayPal give it's "slick" post variables, and what is expected to be in them? Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110029 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 I just renamed / changed something in your script which maybe is what your looking for, but i am pretty sure this while loop isnt right if your fetching array results. Here goes nothing $x = 1; // set the initial item number while(isset($_POST['item'].$x)){ $qty = $_POST['quantity'].$x; // i placed a .$x behind it, while($qty > 0){ // step through each item response result, setting each item to paid $package_id = $_POST['item'].$x; // i placed a .$x behind it, update_paid_status($transaction_id, $package_id); $qty--; } $x++; } Lol but i really just don't know what vars your dealing with Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110031 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 I wrote something for you, maybe this is more as you like it: <?php $paypal_item["monkey"] = "3"; // an array with the name paypal_item, with an item name and quantity $paypal_item["donkey"] = "4"; $paypal_item["frog"] = "6"; $paypal_item["kitty"] = "1"; $paypal_item["lepricorn"] = "8"; $paypal_item["cow"] = "300"; function paypal_custom_function($array){ // a custom function to loop through the paypal array. foreach($array as $item => $quantity){ echo "item: {$item} quantity: {$quantity}.<br />\n"; update_paid_status($transaction_id, $package_id)or die ('error'); echo 'result = succes!<br />'; } } echo paypal_custom_function($paypal_item); //An echo that calls the function and loops through everything gives an error if needed and else succes ?> Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110037 Share on other sites More sharing options...
DavidAM Posted September 11, 2010 Share Posted September 11, 2010 When you put a variable inside of single quotes it is a literal. When you use double quotes, it is interpreted: $x = 1; $key = 'item_number$x'; // $key will be item_number$x $key = "item_number$x"; // $key will be item_number1 Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110043 Share on other sites More sharing options...
fortnox007 Posted September 11, 2010 Share Posted September 11, 2010 When you put a variable inside of single quotes it is a literal. When you use double quotes, it is interpreted: I am gonna learn that quote by heart it's true and catchy Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110045 Share on other sites More sharing options...
BizLab Posted September 12, 2010 Author Share Posted September 12, 2010 GREAT EYE DAVIDAM!!!! And thanks for the help Fortnox All that is left is to work out the processes and i will be 100% thanks to the awesome contributors in this forum When you put a variable inside of single quotes it is a literal. When you use double quotes, it is interpreted: $x = 1; $key = 'item_number$x'; // $key will be item_number$x $key = "item_number$x"; // $key will be item_number1 Quote Link to comment https://forums.phpfreaks.com/topic/213172-paypal-ipn-return-item-data-dynamically-handled-item_number1-2-3-ect-code/#findComment-1110108 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.