如何将css应用于$row["name"]
并将其显示在表格中?
这是我的代码:
<div class="maincontent1">
<?php
$link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link));
$sql = "SELECT id, name, description1 FROM table1";
$result = $link->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
?>
<div class="title-style1">
<?php
echo $row["name"];
?>
</div>
<?php
echo $row["description1"];
}
$link->close();
}
?>
答案 0 :(得分:0)
我不清楚你对css的看法,但如果你想把你的数据打印在表格中那么你可以做这样的事情
<table>
<tr>
<th>
Name
</th>
<th>
Description
</th>
</tr>
<?php
$link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link));
$sql = "SELECT id, name, description1 FROM table1";
$result = $link->query($sql);
if ($result->num_rows > 0)
{
// output data of each row
while($row = $result->fetch_assoc())
{
?>
<tr>
<div class="title-style1">
<td> <?php
echo $row["name"];
?>
</td>
<td>
<?php
echo $row["description1"];
?>
</td>
</div>
</tr>
<?php
}
$link->close();
}
?>
</table>
答案 1 :(得分:0)
可以尝试这样的事情:
<div class="maincontent1">
<?php
$link = mysqli_connect("localhost","root","","webpage2") or die("Error " . mysqli_error($link));
$sql = "SELECT id, name, description1 FROM table1";
$result = $link->query($sql);
if ($result->num_rows > 0) {
?>
<div class="title-style1">
<table name="table" border: 1px solid black ; cellspacing='0'>
<thead>
<tr>
<th style= "" > Name </th> // you can put the style you want here
<th style= "" > Description </th>
</tr>
</thead>
<?php while($row = $result->fetch_assoc()){ ?>
<td style=""> <?php echo $row['name'];?></td> //style here
<td style=""> <?php echo $row['description1'];?></td> //style here
<?php
}
?>
</table>
<?php }
$link->close();
?>
如果你想拥有一个外部css,那么你就可以调用它。我希望这会有所帮助。