Hi guys
So I have a table script and I'm fetching the records from a table.
1st column is a date
2nd column is an int
There is a date search selection on top. So if I select a date range and list the records, it will filter and display the records. If I never do a date selection means it will show that months records by default -
else{
$query=mysqli_query($conn, "SELECT created_at, count(*) AS total, number_click, DATE_ADD(LAST_DAY(created_at),INTERVAL 1 DAY) as 'first_date_of_month' FROM `records` WHERE DATE_FORMAT(created_at, '%Y-%m-%d') BETWEEN 'first_date_of_month' AND NOW() GROUP BY created_at ORDER BY created_at ASC") or die(mysqli_error());
while($fetch=mysqli_fetch_array($query)){
?>
<tr>
<td><?php echo $fetch['created_at']?></td>
<td><?php echo $fetch['total']?></td>
</tr>
and it's working great.
Now what I want to do is, at the bottom, I want to show the SUM of 1 column..
For example -
Over here, I want to show a text Total number of records : XX
Need to replace the XX with the SUM of that 2nd column..
My coding is a little confusing and it's not a standard format because I'm still learning.
I did some online research and I tried using this after the closing PHP tags defining a variable named $cont -
<tfoot>
<tr>
<th style="text-align:right">Total number of clicks:</th>
<!-- <th></th> -->
<th><?php echo $cont; ?></th>
</tr>
</tfoot>
It's working great but it's working only when I do a search using the search button because $cont; variable is defined within the PHP form code. So I if refresh the page I'm getting an error "undefined variable" and I'm not sure how to make it available outside the PHP code.
If it makes it any easier, I've uploaded the code here - https://pastebin.com/75FusdLJ
What I wanted to do now is, add a text after that table and show the total SUM of that 2nd column regardless of the Search button press.
If anyone could share the modified version of the code or at least let me know which portion I should replace with which code I'd really appreciate that.
Thanks.