Chris
Chris

Reputation: 123

How to style td's that are selecting MySQL data

I can't seem to work out how I can style the td's in the following code.

I want the Match Details to be aligned to the right. Normally I would just insert straight in, but this doesn't seem to work.

I also want to bolded the away team row.

Any idea?

Cheers

<h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";

$result = $conn ->query($sql);
if ($result-> num_rows > 0) {
    while($row = $result -> fetch_assoc()) {
        echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td>" . $row["awayteam"] . "</td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td>Match details</td></tr><br>";
    }

 "</table>";
} else {
    echo "No games listed for this month";
}
?></table>

Upvotes: 0

Views: 40

Answers (3)

Gaurang Joshi
Gaurang Joshi

Reputation: 695

to styling your display data you need to apply css code as declared in <style> tag.

<style>
.table-boarderd{
    border: 1px solid black;
    text-align: left;
}
.pull-right{
    text-align: right;
}
.bold{
    font-weight: bold;
}
</style>

<h3>SEPTEMBER 2017</h3>
<table class="table-boarderd">
<?php
$sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";
$result = $conn ->query($sql);
?>

<?php
if ($result-> num_rows > 0) {
    while($row = $result -> fetch_assoc()){ ?>
        <tr>
            <td><?=$row["day"]?></td>
            <td><?=$row["date"]?></td>
            <td><?=$row["month"]?></td>
            <td class="pull-right bold"><?=$row["awayteam"]?></td>
            <td><?=$row["homescore"]?>-<strong><?=$row["awayscore"]?></strong></td>
            <td><?=$row["venue"]?></td>
            <td>ESFA League</td>
            <td>Match details</td>
         </tr><br/>
    <?php } ?>
</table>

<?php }

else {
    echo "No games listed for this month";
}

?>

As I have used custom css with table awayteam cell you can use at anywhere

Upvotes: 1

Twinfriends
Twinfriends

Reputation: 1997

Then you're trying it the false way, because the straight way in is possible. Also you've closed your table twice. I removed it once. Try this:

    <h3>SEPTEMBER 2017</h3>
<table><?php $sql = "SELECT * FROM `results` WHERE `year`='2017' AND `Division`='AA1' AND `month`='September'";

$result = $conn ->query($sql);

if ($result-> num_rows > 0) {
    while($row = $result -> fetch_assoc()){
        echo "<tr><td>" . $row["day"] . ", " . $row["date"] . " " . $row["month"] . "</td> <td><b>" . $row["awayteam"] . "</b></td> <td>" . $row["homescore"] . " - " . $row["awayscore"] . "</td> <td>" . $row["venue"] . "</td> <td>ESFA League</td><td style="text-align: right;">Match details</td></tr><br>";
    }

}

else {
    echo "No games listed for this month";
}

?></table>

Upvotes: 0

Nishant Nair
Nishant Nair

Reputation: 1997

Write the css for the code in head tag

table, th, td {
border: 1px solid black;
text-align: right;
}

Upvotes: 0

Related Questions