我目前正在从事的元素我正在为 admin_level 2 的用户呼应每个已经不是管理员的用户,这样他们就可以让普通用户成为管理员,它会更新数据库在改变他们的水平。
目前它看起来像以下回应用户:
// users
$sth2 = $conn->prepare("SELECT id, username, email, admin_level FROM users WHERE admin_level < 1");
$sth2->execute();
$users = $sth2->fetchAll();
// echo users
if ($result > 1) {
echo "<div class='col-md-6'>";
echo "<p class='title'>Admin Level 2 Panel</p>";
echo "<p class='title2'>Make users administrators in this module.</p>";
echo "<table class='users' border='1'>";
echo "<tr style='font-weight:bold;color:white;'>";
echo "<td class='titles'>ID</td>";
echo "<td class='titles'>Username</td>";
echo "<td class='titles'>Email</td>";
echo "<td class='titles'>Admin Level</td>";
echo "<td class='titles'>New Level</td>";
echo "</tr>";
foreach ($users as $row) {
echo '<center>';
echo '<tr>';
echo '<td class="info">' . $row['id'] . '</td>';
echo '<td class="info">' . $row['username'] . '</td>';
echo '<td class="info">' . $row['email'] . '</td>';
echo '<td class="info">' . $row['admin_level'] . '</td>';
echo '<td class="info2"><a href="#">1</a><a href="#">2</a></td>';
echo '</tr>';
echo '</center>';
echo '</table>';
}
echo "</div>";
}
以下是我用来设置表格/用户样式的 CSS:
table.users{border-collapse:collapse;border-color:silver;text-align:center;width:100%;}
td.titles,td.info{padding:1px;color:white;}
td.info2>a{margin:0 10px;}
我在这里遇到的问题是第一个用户 ($row) 的样式很好,但之后的每个其他用户都不受任何 css 的影响,正如您在此处的屏幕截图中看到的那样:
最佳答案
我只是在这里解释我的评论:
You are closing your table on every loop with
</table>
you should do it after the foreach, so just move it to after the cycle
...
echo "<table>";
...
foreach ($users as $row) {
echo '<center>';
echo '<tr>';
echo '<td class="info">' . $row['id'] . '</td>';
echo '<td class="info">' . $row['username'] . '</td>';
echo '<td class="info">' . $row['email'] . '</td>';
echo '<td class="info">' . $row['admin_level'] . '</td>';
echo '<td class="info2"><a href="#">1</a><a href="#">2</a></td>';
echo '</tr>';
echo '</center>';
}
echo '</table>';
正如@HenriqueBarcelos 所说 <center>...</center>
标签无关紧要。
关于php - 一次设置每个 $row 的样式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37659156/