kat35601 Posted August 18, 2020 Share Posted August 18, 2020 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. } Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/ Share on other sites More sharing options...
gw1500se Posted August 18, 2020 Share Posted August 18, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580735 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 ok so I add a sum(UOMPVOLUMETOTAL) over(partition by cmlstate) as StateTotal in my query I have my total field. What is the proper way to create a line break and echo the total after each state? thanks Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580736 Share on other sites More sharing options...
requinix Posted August 18, 2020 Share Posted August 18, 2020 A line break is a <br>. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580737 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 LOL thanks Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580739 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 whats the best way to insert the <br> and StateTotal after each state and before the next state starts? Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580740 Share on other sites More sharing options...
requinix Posted August 18, 2020 Share Posted August 18, 2020 You don't want to put it inside the table cell? Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580741 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 I want to insert the statetotal after each state instead of a column. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580742 Share on other sites More sharing options...
requinix Posted August 18, 2020 Share Posted August 18, 2020 Repeating your question for the fourth time does not answer mine. Do you want to put the total inside the table cell? Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580743 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 I am sorry yes inside Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580744 Share on other sites More sharing options...
requinix Posted August 18, 2020 Share Posted August 18, 2020 Then put it echo "<tr><td>" . $row['cmlstate']."</td>"; inside the table cell. Stick the <br> and $row[whatever] values in there. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580745 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 I want it to break like this so somewhere I have to say when it gets to the end of the state to echo the total and then start the next state. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580747 Share on other sites More sharing options...
requinix Posted August 18, 2020 Share Posted August 18, 2020 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. Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580748 Share on other sites More sharing options...
kat35601 Posted August 18, 2020 Author Share Posted August 18, 2020 OK Thanks Quote Link to comment https://forums.phpfreaks.com/topic/311344-create-a-total-line-for-each-state/#findComment-1580749 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.