Reputation: 7
I Have an if Statement in the function is to make Row Red... if $ced (which is date value coming from MySQL) is lesser than the current time the code is given below: what I am looking for is how can I get total number of rows like 20,30 or whatever the value is and echo
<tr <?php if(($ced <= time())): ?> style="color:red;" <?php endif; ?>>
<td><?php echo $students_rollno_class;?></td>
<td><?php echo $students_admission_no;?> </td>
<td><?php echo $students_firstname;?></td>
<td><?php echo $students_contact;?></td>
<td><?php echo $students_reference_no;?></td>
<td><?php echo date('d/m/Y', strtotime($students_date));?></td>
<td><?php echo $newformat;?></td>
what I tried is
if(($ced <= time())){
$totalCount=$totalCount+1 ;}
the problem is its giving me a row numbers like 1,1,1,1,2,2,2,2,4,4,4,4 but i am looking for is single total count like 20
I have a box where I want to show total count the code is given below
<div class="info-box-content">
<span class="info-box-text"><?php echo "Course Ended"; ?></span>
<span class="info-box-number"><?php echo $totalCount; ?></span>
</div>
image for reference as the rows are changing to red and i want to show total count in the box
Loop i Created but with this its giving me value of 384 as per picture i have only 188 students
<?php
if(($ced <= time())){
$totalCount=$totalCount+1 ; ?>
<tr <?php if(($ced <= time())): ?> style="color:red;" <?php endif; ?>>
<td><?php echo $students_rollno_class;?></td>
<td><?php echo $students_admission_no;?> </td>
<td><?php echo $students_firstname;?></td>
<td><?php echo $students_contact;?></td>
<td><?php echo $students_reference_no;?></td>
<td><?php echo date('d/m/Y', strtotime($students_date));?></td>
<td><?php echo date('d/m/Y', $ced);?></td>
</tr><?php }}?>
<?php echo $totalCount;?>
and making all rows red
Upvotes: 0
Views: 588
Reputation: 72
Just getting directly in your sql request the data filtered by date $ced <= time()
Doing this, you will access directly to the total count without counter, just by calling count($array)
Upvotes: 0
Reputation: 41
In order for $totalCount++
to do what you're looking for, it needs to be within some kind of a loop.
You also don't want to echo $totalCount++
, you want to echo your variable $totalCount
. This is what contains your total count. The ++
is what increments your value stored in $totalCount
.
Can you please share the remainder of your code so we can see how you are trying to accomplish this?
Upvotes: 1