Note that there are some explanatory texts on larger screens.

plurals
  1. POLoop through $_POST array item_nameX (Dynamically Add Number to End of Variable Name)
    primarykey
    data
    text
    <p>UPDATE: THIS IS SOLVED AND THE WORKING CODE IS PASTED IN THE BOTTOM OF THIS POST. I KEEP THE ORIGINAL POST SO OTHERS CAN READ AND FOLLOW.</p> <p>I have had a big problem going Live with PayPal but think I have found the issue.</p> <p>Look at this screenshot, it is from the pdt.php where customers are redirected to after purchase and it is a real one, did with a real visa: <a href="http://snag.gy/5XCvA.jpg" rel="nofollow">http://snag.gy/5XCvA.jpg</a></p> <p>I have printed the whole TX-id at the top for debugging and here I can see that item_number1=54, quantity1=1 and item_name1=Introduktionsföreläsning.</p> <p>The problem is that these do not show under Produkt, ID and Antal(Product, Id and Quantity) which is used to be presented to the customer. This is because I have the variables set like this:</p> <pre><code>$item_number = $response[item_number]; $item_name = $response[item_name]; $qty = $response[quantity]; </code></pre> <p>and they never get anymore than just item_number, when they need to get "++:ed" to item_number1, item_number2 etc for every product.</p> <p>I have tried to do a lot of changes, for example: </p> <pre><code>for($idx = 1; $idx &lt; $count; $idx ++) { //$item_name .=$idx ++; //$item_name = $item_name++; echo ("&lt;div class='abouttext'&gt;Produkt: ".$item_name."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;ID: ".$item_number."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;Antal: ".$qty."&lt;/div&gt;\n"); echo ("&lt;br /&gt;"); } </code></pre> <p>Where the outcommented lines is where I try to append a number to item_name but I just get "1" or nothing at all as an answer when I need it to be item_name1 and so on.</p> <p>Here is my PDT script: But im pretty sure it can be fixed in this area of code: <a href="http://pastebin.com/L2nyT9q7" rel="nofollow">http://pastebin.com/L2nyT9q7</a></p> <pre><code>$array_keys = array_keys($response); $count = 1; foreach($array_keys as $element) { if (!strncmp('item_number', $element, strlen('item_number'))) $count++; } for($idx = 1; $idx &lt; $count; $idx ++) { if (isset($string1) &amp;&amp; 'item_name' != null) { //$item_name .=$idx ++; //$item_name = $item_name++; echo ("&lt;div class='abouttext'&gt;Produkt: ".$item_name."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;ID: ".$item_number."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;Antal: ".$qty."&lt;/div&gt;\n"); echo ("&lt;br /&gt;"); } } </code></pre> <p>Also: I have read on some forums with people with similar problems and they have gotten replies to use item_nameX as the variable name and I have tried that too, without any other result. If I hardcode <code>$item_number = $response[item_number1];</code> &lt;- where I specify the 1 I will get the correct details. I have tested that.</p> <p>WORKING CODE:</p> <pre><code>$array_keys = array_keys($response); $count = 1; $i = 1; foreach($array_keys as $element) { if (!strncmp('item_number', $element, strlen('item_number'))) $count++; } for($idx = 1; $idx &lt; $count; $idx ++ &amp; $i++) { $item_number = $response[item_number . $i]; $item_name = $response[item_name . $i]; $qty = $response[quantity . $i]; echo ("&lt;div class='abouttext'&gt;Produkt: ".$item_name."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;ID: ".$item_number."&lt;/div&gt;\n"); echo ("&lt;div class='abouttext'&gt;Antal: ".$qty."&lt;/div&gt;\n"); echo ("&lt;br /&gt;"); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload