I have a table with 3 rows.
| id | fullname | email.
In the php code, I have programmed that when someone registers on my site, it can be in active (y) or pending (t) status.
What I want is to have a button called PENDING and when I press it, it will show only the users who are Pending in blue.
Now as it is, the pending users is blue without pressing the button.
Any idea; Thank you in advance..
<!-- Table -->
<?php if($this->data):?>
<table>
<thead>
<tr>
<th>UID</th>
<th>FULLNAME</th>
<th>EMAIL ADDRESS</th>
</tr>
</thead>
<?php
$name = 'ON';
echo '<button type="button" id="buttons"
onclick="myFunction('' . $name . '')">Pending</button>';
?>
<script>
function myFunction(name) {
$('#buttons').toggleClass('active');
$('tr').toggleClass('active');
}
</script>
<style>
.active {
background: purple !important;
}
</style>
<?php foreach ($this->data as $row):?>
<?php if($row->active == t):?>
<?php
$blueColor = 'blue';
$greenColor = '#304030';?>
<tr style="background-color:<?php echo $blueColor ;?>">
<?php else:?>
<?php if($row->active == y):?>
<tr style="background-color:<?php echo $greenColor ;?>">
<?php endif;?>
<?php endif;?>
<td><?php echo $row->id;?></td>
<td><?php echo $row->fullname;?></td>
<td><?php echo $row->email;?></td>
</tr>
<?php endforeach;?>
</table>
<?php endif;?>
</div>
2
Answers
You should try to use addEventListener:
It is not completely clear if the code shown above is how your code is currently or whether it is comprised of portions of your actual code. As it is above that would be invalid markup due to the inclusion of the button, script and style elements in the table. However he following is based upon an understanding (perhaps incorrect) of what you are trying to do