Jump to content

Output Information from an array in to Tables


lanceox

Recommended Posts

Hey,
 
I currently display the product options and the available quantity and everything works fine however I would like this information to be displayed in a table automatically (array form).
 
This currently works using an array and outputs the information below.
 
At the moment it looks like this:
 
8 - 10
12 - 14
16 - 18
34
34
34
 
However I would like it in table form, for example:
 
Size Availability
8 - 10 34
12 - 14 34
16 - 18 34
 
 
<?php foreach ($option['option_value'] as $option_value)
            {
               print ( '<pre>' )  ;
               print_r ($option_value['name']);    
               print ( '</pre>' )  ;
            }
         ?>
       <?php foreach ($option['option_value'] as $option_value)
         {
             print ( '<pre>' )  ;
            print_r ($option_value['quantity']);    
            print ( '</pre>' )  ;
         }
         ?>

If anyone could help that would be great.  I have tried everything.

 

If you need any further details please let me know

 
Link to comment
Share on other sites

Hi

 

Thanks for the helps.

 

This has put them in columns which i would like.  

 

 

Is there anyway that a table with rows and columns could be output aswell.

 

For example below I have entered information (I know its wrong but just to try and explain what I mean)

         <table>
         <?php foreach ($option['option_value'] as $key => $option_value)
            {
         <tr>
               print ( '<pre>' )  ;
               print_r ($option_value['name'] .' '.$option_value['quantity']) ;    
               print ( '</pre>' )  ;
         </tr>
            }
         ?>
</table>

I would like it to be output like this with cells, etc.  Any form of really, just so that it will be output results in a table

 

Size               Availability

8-10                    34

12-14                  34

16-18                  34

20-22                  34

 

Thanks for all help so far

Edited by lanceox
Link to comment
Share on other sites

Hi,

 

thanks for your answer.  what I mean is that, at the moment the array prints out a products sizes (which can vary and also availability).

 

So when considering the following code:

         <?php foreach ($option['option_value'] as $key => $option_value)
            {
               print ( '<pre>' )  ;
               print_r ($option_value['name'] .' '.$option_value['quantity']) ;    
               print ( '</pre>' )  ;
            }
         ?>

The for loop will print out all whatever the sizes and quantities are listed, however I would like it to add another row for any additional sizes.

 

I think this should be within the for loop and print <new row> everytime $option_value['name'] is printed and then <new column then new row> everytime $option_value['quantity']).

 

Size               Availability

8-10                    34

12-14                  34

16-18                  34

20-22                  34

 

Hope this helps more

 

Thanks guys

Link to comment
Share on other sites

When I use this code it prints out array information.  I changed it slightly (i.e. variables) and it only prints one size.

 

The code is use is:

                <?php
		{
			echo'<pre>';
			var_export($option_value['name'].' '.$option_value['quantity']);
			echo '</pre>';
		}
		?>

The output i get is:

 

'16 - 18 34'

 

Thanks

Link to comment
Share on other sites

Thanks for your help in all but I may have confused you.  what I would like

 

Everything outputs great but can a table be included within the for loop so that no matter how many or few fields are printed; the size and availability will have its own row and column

 

<table>

 

Column 1 (simply to explain)                      Column2 (simply to explain)

Size (own box)                                                 Availability

8-10 (own box)                                                           34 (own box)

12-14 (own box)                                                         34 (own box)

16-18 (own box)                                                         34 (own box)

20-22 (own box)                                                         34 (own box)

 

</table>

 

Thanks and again, sorry for confusion

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.