lanceox Posted June 11, 2013 Share Posted June 11, 2013 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 Quote Link to comment Share on other sites More sharing options...
gristoi Posted June 12, 2013 Share Posted June 12, 2013 <?php foreach ($option['option_value'] as $key => $option_value) { print ( '<pre>' ) ; print_r ($option_value[$key]['name'] .' '.$option_value[$key]['quantity']) ; print ( '</pre>' ) ; } ?> Quote Link to comment Share on other sites More sharing options...
lanceox Posted June 13, 2013 Author Share Posted June 13, 2013 (edited) 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 June 13, 2013 by lanceox Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 HTML syntax for a table is <table> <tr> <td> name1 </td> <td> qty1 </td> </tr> <tr> <td> name2 </td> <td> qty2 </td> </tr> </table> so put the data items inside <td>...</td> cells Quote Link to comment Share on other sites More sharing options...
lanceox Posted June 13, 2013 Author Share Posted June 13, 2013 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 can you post the output from this code echo'<pre>'; var_export($option); echo '</pre>'; Quote Link to comment Share on other sites More sharing options...
lanceox Posted June 13, 2013 Author Share Posted June 13, 2013 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 Quote Link to comment Share on other sites More sharing options...
Barand Posted June 13, 2013 Share Posted June 13, 2013 Good luck Quote Link to comment Share on other sites More sharing options...
lanceox Posted June 13, 2013 Author Share Posted June 13, 2013 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 Quote Link to comment 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.