Reputation: 123
I'm just having a play around with a basic table with input from a form on another page.
I want to change the CSS of table in depending on the result of the game.
If the home team wins I want the background colour of the row to be gree if they loose then red, otherwise remain the same.
So I figured I'd need to use IF and ELSES, however not quite sure how to integrate that with CSS and where to put it.
I'm still very new with PHP.
<html>
<head>
<title>Player Stats</title>
<style>
table {
font-family: arial, sans-serif;
border-collapse: collapse;
width: 100%;
}
td, th {
border: 1px solid #dddddd;
text-align: left;
padding: 8px;
}
tr:nth-child(even) {
background-color: #dddddd;
}
</style>
</head>
<body>
<h1>Player Stats</h1><br>
</br>
<h3>Results</h3><br>
</br>
<table>
<tr>
<th>Home team</th>
<th>Away team</th>
<th>Score</th>
<th>Venue</th>
<tr>
<td><?php echo $_POST["home"]; ?></td>
<td><?php echo $_POST["away"]; ?></td>
<td><?php echo $_POST["goalsh"]; ?> - <?php echo $_POST["goalsa"]; ?></td>
<td><?php echo $_POST["formGender"]; ?></td>
</tr>
</table>
<br>
</br>
<a href="http://chrispaton.xyz/update.php">Update player stats</a>
</body>
</html>
Upvotes: 2
Views: 72
Reputation: 3342
One way would be to make two classes, red and green.
.red{ background-color: red }
.green{ background-color: green }
You could do something like,
<tr class="<?= (!($_POST["goalsa"] > $_POST["goalsh"])) ? 'green' : (($_POST["goalsa"] > $_POST["goalsh"])? 'red' : '') ?>" />
Upvotes: 1