我需要在“注释”列中的某些行中添加删除线,以使其包含“旧”一词。 我正在使用连接到sql数据库的php代码。 是否有任何有关此操作的示例代码?
这是我正在使用的当前代码:
<?php
$con=mysqli_connect("localhost", "root", "") or die("Error connecting to database: ".$mysqli->error);
mysqli_select_db($con, 'mysql') or die(mysqli_error($con));
$result= $con->query("SELECT * FROM `cloud_team` WHERE `Vendor` = 'cisco' ORDER BY `customer_name` DESC") or die($mysqli->error);;
echo "<table align='center' border='3' cellspacing='1' cellpadding='1'>";
echo "<thead><th style='background-color:#00ffff'>customer number</th><th style='background-color:#00ffff'>customer name</th><th style='background-color:#00ffff'>Platform</th><th style='background-color:#00ffff'>MGMT IP</th><th style='background-color:#00ffff'>Current Version</th><th style='background-color:#00ffff'>Recommended Version</th><th style='background-color:#00ffff'>Last Version</th><th style='background-color:#00ffff'>GUI User</th><th style='background-color:#00ffff'>Serial</th><th style='background-color:#00ffff'>date</th><th style='background-color:#00ffff'>Notes</th></thead>";
$i=1;
while($row = mysqli_fetch_assoc($result)) {
if($i%2==0)
{
echo '<tr bgcolor="#FFFF00">';
}
else
{
echo '<tr bgcolor="#99FFCC">';
}
$i++;
echo "<a ='send.php'>" . "<td> " . $row['customer_number'] . "<td> " . $row['customer_name'] . "<td> " . $row['Platform'] . " <td> " . $row['MGMT_IP'] . " <td> " . $row['Version'] . " <td> " . $row['recommended_version'] . " <td> " . $row['last_version'] . " <td> " . $row['GUI_User'] . "<td> " . $row['serial'] . "<td> " . $row['Service_contract'] . "<td> " .$row['Notes']. "</a></td>";
echo "<td><a href='/cloudpass/viewpass.php?id=".$row['ID']."' target=\"_blank\" class='btn btn-warning btn-sm'>View Password</a></td>";
echo "</tr>";
}
echo "</table>";
$con->close;
?>
谢谢
答案 0 :(得分:1)
首先,为删除线设置CSS类:
<style>
.old-row {
text-decoration: line-through;
}
</style>
然后,创建一个变量来知道何时在循环中应用删除线:
$add_strikethrough = '';
if (preg_match('/\bold\b/',$row['Notes']))
$add_strikethrough = ' old-row':
}
最后,将该类添加到输出的每一行:
if($i%2==0)
{
echo "<tr bgcolor='#FFFF00' class='$add_strikethrough'>";
}
else
{
echo "<tr bgcolor='#99FFCC' class='$add_strikethrough'>";
}