0

这是我的 PHP 编码,我使用 select where 语句从我的数据库中获取数据并输出它。我正在尝试更改打印语句上的文本属性,例如字体、颜色和大小,任何人都可以帮助解决这个问题吗?

<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        print " - Name: " . $row["fname"]. " " . $row["sname"]. "<br>";
    }
} else {
    echo "0 results";
}

mysqli_close($conn);
?>
4

4 回答 4

2

<ul>您可以使用 HTML和<li>元素对列表进行样式设置。

<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>Stylists</title>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
$servername = "";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}

$sql = "SELECT fname, sname FROM tbl_stylist WHERE fname = 'liza'";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    echo "<ul>";

    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "<li>Name: " . $row["fname"]. " " . $row["sname"]. "</li>";
    }
    echo "</ul>";
} else {
    echo "0 results";
}

mysqli_close($conn);
?></body>
</html>

并输入css/style.css这样的内容:

li {
   color: red;
   font-weight: bold;
   font-size: 12pt;
}

您还可以将样式内联放在 head 部分:

<style type="text/css">
li {
   color: red;
   font-weight: bold;
   font-size: 12pt;
}
</style>
于 2018-03-09T09:31:23.387 回答
1

你可以像这样输出你的降价:

print "<div class = 'sampleclass'>  - Name: " . $row["fname"]. " " . 

然后通过在附件中包含以下内容来设置它的css样式

.sampleclass {
    font-size: 15px;
}
于 2018-03-09T09:27:23.257 回答
0

这只是关于 HTML 和 CSS,您可以使用 echo 直接在 HTML 标记中输出字符串。该脚本需要封装到 HTML 的主体和一个预定义的 CSS 类中以进行样式设置:

<!doctype html>
<html>
  <head>
    ....
    <style type="text/css">
      .redBold {
         color: red;
         font-weight: bold;
      }
    </style>
  </head>
  <body>
    <?php
      ....
      echo '<span class="redBold">This text is red and bold</span>';
    ?>
  </body>
</html>

当然你也可以使用内联样式:

<span style="color: red; font-weight: bold;">Also this works</span>

于 2018-03-09T09:28:41.123 回答
0

您始终可以使用 CSS 文件并定义值。例如:

body {
  font-family: arial;
  font-size: 15px;
}
<html>
  <head>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    php txt
  </body>
</html>

此外,您可以使用<span>标签并设置它们的样式。例如,使用 php 的“打印”打印这个跨度:

<span style="font-family: arial; font-size: 15px;">text</span>
于 2018-03-09T09:29:19.557 回答