[英]How do I style specific words when it gets fetched from my MySQLI database in PHP
I have data being fetched from MySQLI database.我从 MySQLI 数据库中获取数据。 I want to style "Small" so it looks like this:
我想设置“小”的样式,所以它看起来像这样:
Here is what my table looks like in PHP.这是我的表在 PHP 中的样子。 I am unsure how to style specific words from fetched data.
我不确定如何从获取的数据中设置特定单词的样式。
Here's my PHP code:这是我的 PHP 代码:
<?php
$connect = mysqli_connect( 'placeholder','placeholder','placeholder','placeholder');
$sql = "SELECT * FROM databasename";
$result = $connect->query($sql);
if ($result->num_rows > 0) {
while ($row = $result-> fetch_assoc()) {
echo "<tr><td>" . $row["item_name"] . "</td>
<td>" . $row["item_cooldown"] . "</td>
<td>" . $row["item_effect"] . "</td>
<td>" . $row["item_passive"] . "</td>
<td>" . $row["item_cost"] . "</td>
<td>" . $row["item_type"] . "</td>
<td>" . $row["item_size"] . "</td></tr>";
}
}
else {
echo "No Results";
}
$connect->close();
?>
</table>
Any help is very appreciated.非常感谢任何帮助。
Add a span inside the related cell (the last td tag pair) and make a css class to style it.在相关单元格(最后一个 td 标签对)内添加一个跨度,并制作一个 ZC7A628CBA22E28EB17B5F5C6AE2A266AZ class 来设置它的样式。
You could even have different colours for different data if you make a base class and a modifier class that is either applied using if/else or switch, or just use the data as the class name if they're single-word.如果您制作基本 class 和使用 if/else 或 switch 应用的修饰符 class 或仅使用数据作为 class 名称(如果它们是单字名称),您甚至可以为不同的数据使用不同的颜色。
to your last <td> tag change it to:将您的最后一个 <td> 标记更改为:
<td style='backgroundColor:green'> ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.