简体   繁体   English

从 PHP 中的 MySQLI 数据库中获取特定单词时,如何设置特定单词的样式

[英]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 标签对)内添加一个跨度,并制作一个 ZC7A62​​8CBA22E28EB17B5F5C6AE2A266AZ 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.

相关问题 如何使用从数据库中获取的数据填充 javascript 变量? - How do I populate a javascript variable with data fetched from a database? 如何使用 mysqli 和 javascript 更新我的数据库 - How do I update my database with mysqli and javascript 如何从搜索表单中阻止网站上的特定搜索词 - How do i block specific search words on my website from my search form 如何将div样式更改为数据库中的值? - how do I change my div style to a value that is from my database? 如何以特定格式将从 ajax 获取的文本附加到我的 html 代码中? - How can I append text fetched from ajax to my html code in a specific format? 如何在预先输入的Bootstrap中使用通过MySQLi从数据库中获取的数据? - How can I use the data I get from my database using MySQLi, in Bootstrap typeahead? 我如何找到element.style()从中动态获取其值的行或脚本文件 - How do i find the line or the script file from which the element.style() gets its values dynamically 如何在 useState 中使用从 DB 获取的数据? - How do I use data that I fetched from DB in useState? 当我的计数器到达我的数组末尾时如何重置我的计数器? - How do I reset my counter when it gets to the end of my array? 当有人单击“垃圾箱”图标时,如何删除特定的 localStorage,它会在前端而不是本地删除它 - How do I delete a specific localStorage when someone click a “trash” icon, which gets rid of it frontend but not local
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM