0

This is my array

    $_tierPrices = Array
     (
    Array
        (   
            "price_qty" => "4",
            "price" => "143.00",
            "savePercent" => "8"      
        ),

    Array
        (   
            "price_qty" => "12",
            "price" => "133.0000",
            "savePercent" => "15"
        ),

    Array
        (   
            "price_qty" => "20",
            "savePercent" => "18",
            "price" => "128.0000"
        ),

    Array
        (
            "price_qty" => "40",
            "savePercent" => "21",
            "price" => "123.0000"
        )
     );

I want to set this array value in table format as shown below:

enter image description here

Please advice

closed as off-topic by Marius Apr 21 '16 at 13:49

  • This question does not appear to be about the Magento e-Commerce platform within the scope defined in the help center.
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Your scope is to show the prices in a table right? – Mujahidh Apr 21 '16 at 9:12
  • Yes in given format – Purushotam Sharma Apr 21 '16 at 10:30
  • I'm voting to close this question as off-topic because it's not about magento. – Marius Apr 21 '16 at 13:49
2

I have tested this and it works fine.

Tier Price Array

<?php
    $_tierPrices = array (
        array
        (
            "price_qty" => "4",
            "price" => "143.00",
            "savePercent" => "8"      
        ),

        array
        (   
            "price_qty" => "12",
            "price" => "133.0000",
            "savePercent" => "15"
        ),

        array
        (   
            "price_qty" => "20",
            "savePercent" => "18",
            "price" => "128.0000"
        ),

        array
        (
            "price_qty" => "40",
            "savePercent" => "21",
            "price" => "123.0000"
        )
    );
?>

Tier Price Table

<table>
    <tr><td>Header</td></tr>
    <?php $_qtyRow = '<tr>'; ?>
    <?php $_priceRow = '<tr>'; ?>
    <?php $_saveRow = '<tr>'; ?>
    <?php
        foreach($_tierPrices as $_tierPrice) {
            $_qtyRow .= '<td>'.$_tierPrice['price_qty'].'</td>';
            $_priceRow .= '<td>'.$_tierPrice['price'].'</td>';
            $_saveRow .= '<td>'.$_tierPrice['savePercent'].'</td>';
        }

        $_qtyRow .= '</tr>';
        $_priceRow .= '</tr>';
        $_saveRow .= '</tr>';

        echo $_qtyRow;
        echo $_priceRow;
        echo $_saveRow;
    ?>
    <tr><td>Footer</td></tr>
</table>

I hope this will help.

2
Please find below answer for your customization


<?php
$_tierPrices = array
(
    array
        (   
            "price_qty" => "4",
            "price" => "143.00",
            "savePercent" => "8"      
        ),

    array
        (   
            "price_qty" => "12",
            "price" => "133.0000",
            "savePercent" => "15"
        ),

    array
        (   
            "price_qty" => "20",
            "savePercent" => "18",
            "price" => "128.0000"
        ),

    array
        (
            "price_qty" => "40",
            "savePercent" => "21",
            "price" => "123.0000"
        )
);
$sizeof_array = sizeof($_tierPrices);
?>


<table width="200" border="1">
<tr>
<td colspan="<?php echo $sizeof_array;?>">&nbsp;</td>
</tr>
<tr>
<?php for ($row = 0; $row < $sizeof_array; $row++)
{?>
<td>
<table width="200" border="0">
<tr>
<td><?php echo "price_qty".$_tierPrices[$row]['price_qty']?></td>
</tr>
<tr>
<td><?php echo "savePercent".$_tierPrices[$row]['savePercent']?></td>
</tr>
<tr>
<td><?php echo "price".$_tierPrices[$row]['price']?></td>
</tr>
</table>
</td>
<?php }?>
</tr>
<tr>
<td colspan="<?php echo $sizeof_array;?>">&nbsp;</td>
</tr>
</table>

check the image for out put visualenter image description here

You can use this method to do your customisation.

1
  <?php $_tierPrices = Array
    (
        Array
            (   
                "price_qty" => "4",
                "price" => "143.00",
                "savePercent" => "8"      
            ),

        Array
            (   
                "price_qty" => "12",
                "price" => "133.0000",
                "savePercent" => "15"
            ),

        Array
            (   
                "price_qty" => "20",
                "savePercent" => "18",
                "price" => "128.0000"
            ),

        Array
            (
                "price_qty" => "40",
                "savePercent" => "21",
                "price" => "123.0000"
            )
    ); ?>

<table border="1">
<tr><td colspan="<?php echo count($_tierPrices) ?>">Header</td></tr>
<?php 
$htmlprice="<tr>";
$htmlsavePercent="<tr>";
$htmlsaprice="<tr>";
foreach($_tierPrices as $tier) { 

  $htmlprice .='<td>'.$tier['price_qty'].'</td>';

  $htmlsavePercent .='<td>'.$tier['savePercent'].'</td>';
  $htmlsaprice .='<td>'.$tier['price'].'</td>';
} 
$htmlprice .="</tr>";
$htmlsavePercent .="</tr>";
$htmlsaprice .="</tr>";

echo $htmlprice;
echo $htmlsavePercent;
echo $htmlsaprice;
?>
<tr><td colspan="<?php echo count($_tierPrices) ?>">footer</td></tr></table>

output

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.