Angelojoseph17 Posted December 12, 2012 Share Posted December 12, 2012 I have the folllowing loop which only displays the last part of the array: $i = 0; // create a varible that will tell us how many items we looped over foreach ($listprint as $key => $value) { $i++; $content2 = " <tr> <th>Qty</th> <th>Description</th> <th>ProductNumber</th> <th>Issue</th> </tr> <tr > <td>" . $value['Quantity'] . "</td></a> <td>" . $value['Description'] . "</td></a> <td>" . $value['ProductNumber'] . "</td></a> <td>" . $value['Issue'] . "</td></a> </tr> </table> "; } The array Array ( [0] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Tewksbury [ProductNumber] => 2323/3232 [Quantity] => 5 [issue] => Holes in lining ) [1] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Ryder Sahara Boots [ProductNumber] => 34343/232 [Quantity] => 2 [issue] => Ripped Lining ) [2] => Array ( [ReferenceNumber] => 4543/2323/ [CustomerNumber] => CHU15 [CustomerName] => AngeloJoseph [Description] => Oxford Brogues [ProductNumber] => 23232/323 [Quantity] => 1 [issue] => Broken Last ) ) Quote Link to comment https://forums.phpfreaks.com/topic/271906-for-each-loop-not-display-all-contents-of-arrary/ Share on other sites More sharing options...
Muddy_Funster Posted December 12, 2012 Share Posted December 12, 2012 by using $content = you are overwriting the $content variable each time you run through the loop, thus you will only get the last result. do something like foreach(......){ if(!isset($content)){ $content = "your string here"; } else{ $content .= "your string here"; } Quote Link to comment https://forums.phpfreaks.com/topic/271906-for-each-loop-not-display-all-contents-of-arrary/#findComment-1398928 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.