1

I have a page that show my orders in day, but now i want to count and sum the values from 7 / 15 and 30 days ago (if possible in list), or just count/sum in this step: <strong>Soon</strong>

$pedido->valor_pedido is my value from order
$pedido->id its id from order, i use to count.

My code:

<div class="row">

<?php

$totalPedido = 0;
$contagPedido = 0;

foreach ($pedidos as $pedido) {
    $totalPedido += $pedido->valor_pedido; // sum day orders
    $contagPedido += count($pedido->id); //count day orders
}
?>
    <div class="span12">
    <!-- Widgets -->
        <ul class="widgets">
    <!-- Basic widget item -->
            <li class="span3">
                <span class="widget-label"><span class="awe-star"></span> This Week</span>
                <strong>Soon</strong>
            </li>
    <!-- /Basic widget item -->
    <!-- Clickable widget item -->
            <li class="span3">
                    <span class="widget-label"><span class="awe-star"></span> Totay</span>
                    <strong>R$ <?= ConverteReal($totalPedido) ?></strong> 
            </li>
    <!-- /Clickable widget item -->
    <!-- Widgets with graphs -->
            <li class="span3">
                <span class="widget-label"><span class="awe-star"></span> Orders this week</span>
                <strong>Soon</strong>
            </li>
            <li class="span3">
                <span class="widget-label"><span class="awe-star"></span> Orders today</span>
                <strong><?= $contagPedido ?></strong>   
            </li>
    <!-- /Widgets with graphs -->
        </ul>
    <!-- /Widgets -->
    </div>
</div>
1
  • why are you using count() with $pedido->id ... as per php manual Count all elements in an array Commented Aug 15, 2019 at 15:26

1 Answer 1

2

According to PHP Manual, count() will use to get the count of all elements in an array

If $pedido->id is a unique ID, you can just get the count of $pedidos array like

<?
$contagPedido = count($pedidos); // total no of orders 
foreach ($pedidos as $pedido) {
    $totalPedido += $pedido->valor_pedido; // sum day orders    
}
?>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.