Reputation: 303
$row['attended']
can be either 'YES' or 'NO' (strings). I want to hide every row that has 'Attended' as 'NO'. So in pseudo code:
if (<tr> contains 'NO') {
hide that row (<-That's the tricky part to me)
}
My code is on the server side, but I'd be happy to echo out some JavaScript if that's what's necessary.
<?php
include 'connect2.php';
date_default_timezone_set('Europe/Lisbon');
$today = date('Y-m-d');
$sql="Select * FROM detentions WHERE date = '$today'";
$result = mysqli_query($con,$sql);
echo "<center><table style='width:400px; border:3px solid #444'>
<tr>
<th style='background-color:#444'>First</th>
<th style='background-color:#444'>Last</th>
<th style='background-color:#444'>Attended</th>
<th style='background-color:#444'></th>
</tr>";
while($row=mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['fname'] . "</td>";
echo "<td>" . $row['lname'] . "</td>";
echo "<td><center>" . $row['attended'] . "</center></td>";
echo "<td><button type = 'button' class='unattended button-error pure-button button-xsmall' style='float:right; margin-left:0.2cm' name='" . $row['lname'] . "' id='" . $row['fname'] . "'><b>Unattended</b></button> <button type = 'button' class='editDet2 button-success pure-button button-xsmall' style='float:right' id=" . $row['det_id'] . "><b>Attended</b></button></td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
Upvotes: 0
Views: 185
Reputation:
You can add a WHERE clause unto your SELECT statement, which specifies that the Attended field should be equal to no. This would prevent the unwanted rows from being returned in the first place.
Change your SELECT statement to:
SELECT * FROM detentions WHERE date = '$today' AND attended='yes'
Upvotes: 1
Reputation: 444
replace your select statement
$sql="Select * FROM detentions WHERE date = '$today' AND attended = 'YES' OR attended = ''";
and remove your if condition.
Upvotes: 1
Reputation: 682
Another option is to skip the record with $row['attended']="No" in your while statement... An "if ($result.attended=='yes') {add ...} stamement" will do... Though the more efficient and elegant way would be to add a clause on the query statement like:
Select * FROM detentions WHERE date = '$today' and attended='yes'"
As suggested on the previous answer...
Upvotes: 2