【问题标题】:How can I style my php code result?如何设置我的 php 代码结果的样式?
【发布时间】:2016-01-23 01:32:23
【问题描述】:

我写了这段代码,我想用 css 设置它的样式。我为其添加了样式,但出现了相同的结果,任何人都可以帮忙。

<p>
<phpcode> 
<?php           
$term = mysql_real_escape_string($_REQUEST['term']);
$servername = "localhost";
$username = "***********";
$password = "***********";
$dbname = "*************";
$conn = new mysqli($servername, $username, $password, $dbname); 
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}   

$sql = "SELECT Install ,  power , RPM FROM SN WHERE serial = '$term'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

    while($row = $result->fetch_assoc()) {
        echo "serial number: " . $term.'<br>';
        echo "installation: " . $row["Install"].'<br>';
        echo "power: " . $row["power"].'<br>';
        echo "RPM: " . $row["RPM"].'<br>';

    }
} else {
    echo "no result";
}
$conn->close();         
?> 
</phpcode>
</p>

【问题讨论】:

  • 不清楚你在问什么,但是 PHP 中有 highlight_file() 来美化代码~不知道你是不是这个意思
  • 你能澄清你的问题吗?此外,代码对 sql 注入开放 - 在 mysqli 中使用准备好的语句会更好!
  • 欢迎来到 Stack Overflow!请查看有关 Stack Overflow 的How to ask 问题以及can be asked 的问题类型以及should be avoided. 的问题类型

标签: php css


【解决方案1】:
<style>
    .results div:nth-of-type(1){
        color:red;
        background:blue;
        font-size:3rem;
    }
    .results div:nth-of-type(2){
        color:blue; 
        background:yellow;
        font-size:2rem;
    }
    .results div:nth-of-type(3){
        color:green;
        background:orange;
        font-size:1rem;
    }
    .results div:nth-of-type(4){
        color:orange;
        background:black;
        font-size:0.5rem;   
    }
</style>




    while( $row = $result->fetch_assoc() ) {
        echo "
        <div class='results'>
            <div>serial number:{$term}</div>
            <div>installation:{$row['install']}</div>
            <div>power:{$row['power']}</div>
            <div>rpm:{$row['rpm']}</div>
        </div>";
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-10-05
    • 2020-08-13
    • 2018-02-19
    • 2023-03-23
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多