我对PHP很新。如何将css样式添加到$ output?例如。 font-family,或者将它放入带有类的样式的div中。
表格处理代码:
require_once("connect.php");
if (!$db_server) {
die("Unable to connect to MySQL: " . mysqli_connect_error());
} else {
mysqli_select_db($db_server, $db_database);
$query = "SELECT * FROM ingredients WHERE dietID='".$_SESSION['dietID']."'";
$result = mysqli_query($db_server, $query);
if (!$result)
die("Query failed: " . mysqli_error($db_server));
while ($row = mysqli_fetch_array($result)) {
$str_options .= "<option value='" . $row['ID'] . "'>";
$str_options .= $row['ingredient'];
$str_options .= "</option>";
}
}
数据库的输出结果为:
<?php
echo $output;
?>
答案 0 :(得分:1)
就像在HTML中一样:
$output .= '<div style="font-family: sans-serif">My Div</div>'
或者您可以添加完整的<style>
元素:
$output .= '<style>div{ font-family: sans-serif; }</style>'
一个班级:
$output .= '<div class="myClass">My Div</div>'
$output .= '<style>.myClass{ font-family: sans-serif; }</style>' // but this should go in the CSS file