Jump to content

Create a Total Line for each State.

Recommended Posts

In this report I want to create a line break and a Total line for each State.


 while ($row = odbc_fetch_array($result))
    echo "<tr><td>" .  $row['cmlstate']."</td>";
    echo "<td>" .  $row['cmlpostcode']."</td>";
    echo "<td>" .  $row['cmlcity']."</td>";
    echo "<td>" .  $row['ompSalesOrderID']."</td>";
    echo "<td>" .  $row['cmoName']."</td>";
    echo "<td>" .  number_format($row['UOMPVOLUMETOTAL'],2)."</td>";
    echo "<td>" .  number_format($row['UOMPTOTALBOXCOUNT'],0)."</td>";
    echo "<td>" .  $row['Hold']."</td></tr>"; 

I want to sum 'UOMPVOLUMETOTAL' for each state and create a line break between it and the next state.


Link to post
Share on other sites

You need to 'ORDER BY' in your query on state. Then keep a running total of 'UOMPVOLUMETOTAL' until the state changes or you reach the end or your data. At that point output your total and line break and reset the total to 0.

Link to post
Share on other sites

That's not very good table design, but whatever.

You're running a second query to get totals, right? Have the query return a count of rows too. (So AL has 10 rows, AR has 5, and so on.)

Before your loop, start a counter at 0. Increment the counter every time you print a row. When that counter reaches the number of rows the state has, print out a separate <tr> row with the information you want. Then reset the counter to 0 for the next state's rows.

Link to post
Share on other sites

Join the conversation

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

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.