【问题标题】:Styling of php echo table th tagsphp echo table th标签的样式
【发布时间】:2018-03-29 01:15:12
【问题描述】:

我在多个页面中有回显表标签,我想通过为回显 tr 标签提供一个类来设置表的 tr 标签样式,并在我的 css 文件中定义该类的 css。我怎样才能做到这一点?我的查看页面代码在这里:

<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>

【问题讨论】:

  • 这个问题的状态如何?有人好心在下面发布了答案,但您甚至没有在它下面发表评论或接受答案。那么,你说什么?

标签: html forms html-table echo


【解决方案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>

【讨论】:

  • I pulled for ya here...,但 OP 似乎不知道这里的工作原理。
  • @FunkFortyNiner 看起来像是对这个网站的运作方式不感兴趣但只希望有人为他们做这项工作的人之一 :-)
  • 我们经常遇到这些。哦,好吧,我猜是 c'est la vie。
猜你喜欢
  • 2016-03-11
  • 1970-01-01
  • 1970-01-01
  • 2011-07-11
  • 1970-01-01
  • 2016-10-16
  • 2022-11-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多