我在多个页面中有echo表标签,我想通过给一个类来回显tr标签并在我的css文件中定义类的css来设置表的tr标签的样式。我怎样才能做到这一点?我的观看页面代码在这里:
<html>
<head>
<title>View Records</title>
</head>
<body>
<?php
include('connection.php');
$count=1;
$result=@mysql_query("SELECT * FROM form")
or die(mysql_error());
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Password</th> <th>Email</th> <th>Contact Number</th><th>Edit</th><th>Delete</th></tr>";
while ($row=mysql_fetch_array($result)) {?>
<tr>
<td align="center"><?php echo $row["id"]; ?></td>
<td align="center"><?php echo $row["fname"]; ?></td>
<td align="center"><?php echo $row["lname"]; ?></td>
<td align="center"><?php echo $row["pwd"]; ?></td>
<td align="center"><?php echo $row["eml"]; ?></td>
<td align="center"><?php echo $row["num"]; ?></td>
<td align="center"><a href="editrecord.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
<td align="center"><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a></td>
</tr>
<?php $count++; } ?>
}
</table>";
?>
<p><a href="index.php">Add a new Record</a></p>
</body>
</html>
&#13;
答案 0 :(得分:1)
最简单的方法:分配你想要的类。也不要回复来自php的html,更清晰的方式将其直接保存为html:
<html>
<head>
<title>View Records</title>
</head>
<body>
<?php
include('connection.php');
$count=1;
$result=@mysql_query("SELECT * FROM form")
or die(mysql_error());
?>
<table border='1' cellpadding='10'>
<tr class="class_i_choose"> <th>ID</th> <th>First Name</th> <th>Last Name</th> <th>Password</th> <th>Email</th> <th>Contact Number</th><th>Edit</th><th>Delete</th></tr>
<?php while ($row=mysql_fetch_array($result)) {?>
<tr class="a_class_from_my_css">
<td align="center"><?php echo $row["id"]; ?></td>
<td align="center"><?php echo $row["fname"]; ?></td>
<td align="center"><?php echo $row["lname"]; ?></td>
<td align="center"><?php echo $row["pwd"]; ?></td>
<td align="center"><?php echo $row["eml"]; ?></td>
<td align="center"><?php echo $row["num"]; ?></td>
<td align="center"><a href="editrecord.php?id=<?php echo $row["id"]; ?>">Edit</a></td>
<td align="center"><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a></td>
</tr>
<?php $count++; } ?>
}
</table>";
?>
<p><a href="index.php">Add a new Record</a></p>
</body>
</html>