Representing an array in a specific form of table format in a CodeIgniter view file?

I have an array in the following format. There were about 100 elements in the same format in this array. I want to represent the entire array in a specific table format using the DOMPDF library using codeIgniter.

 result = Array( [0] => Array ( ['brand'] => x, ['product'] =>p1, ['language']=>English, ); [1] => Array ( ['brand'] => x, ['product'] =>p2, ['language']=>English, ); ); 

I like to represent them in a lower format using <table> tags in html .

  Brand xy Product p1 p2 Language English English 

I am looking for ideas. I have such array elements, and not 2 more than 100. I want to loop them.

So, after the request below I will send my code.

 <?php foreach($result as $res) { <table> <tr> <td>Brand</td> <td><?php echo $res['brand'] ?></td> </tr> <tr> <td>Product</td> <td><?php echo $res['product'] ?></td> </tr> <tr> <td>Language/td> <td><?php echo $res['language'] ?></td> </tr> </table> } 

This will give you a way out for one product like this. Brand x
Product p1
English language

How can I do a loop for other products to get information on how I want above?

Note: not only 3 fields in each element of the array. I have more than 30 fields. Maybe you think that I am going this way only because of the ability to print on a PDF page.

+4
source share
2 answers

@Vengat, the following encodings work well. Try this one ...

 <?php $result = Array( 0 => Array ( 'brand' => 'x', 'product' =>'p1', 'language'=>'English', ), 1 => Array ( 'brand'=> 'y', 'product' =>'p2', 'language'=>'English', ) ); echo '<table>'; echo '<tr><td>Brand</td>'; foreach($result as $res) { echo "<td>".$res['brand']."</td>"; } echo '</tr>'; echo '<tr><td>Product</td>'; foreach($result as $res) { echo "<td>".$res['product']."</td>"; } echo '</tr>'; echo '<tr><td>Language</td>'; foreach($result as $res) { echo "<td>".$res['language']."</td>"; } echo '</tr>'; echo '</table>'; ?> 

Output:

 Brand xy Product p1 p2 Language English English 

Use css to align.

+4
source

Use foreach to get each array from an array of results. and use multiple array (row[ ][ ]) with key . you can print <tr><td> everything in echo .

+5
source

All Articles