如何设置选择MySQL数据的样式

时间:2017-01-05 12:27:10

标签: php mysql

我似乎无法弄清楚如何在以下代码中设置td的样式。

我希望匹配详细信息与右侧对齐。通常我会直接插入,但这似乎不起作用。

我也希望加强球队的排名。

有什么想法吗?

干杯

<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>

3 个答案:

答案 0 :(得分:1)

为您的显示数据设计样式,您需要应用<style>标记中声明的css代码。

<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";
}

?>

由于我使用自定义css与表 awayteam 单元格,您可以在任何地方使用

答案 1 :(得分:0)

为头标记中的代码编写css

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

答案 2 :(得分:0)

然后你以错误的方式尝试它,因为直接进入是可能的。你也两次关闭你的桌子。我删除了一次。试试这个:

    <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>