Jump to content

For Each Loop Not Display All Contents Of Arrary


Angelojoseph17

Recommended Posts

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 ) )

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";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.