我正在尝试将<?php if($page===$x) {echo ' class="selected"';}?>
之类的if条件用于在我的分页中使用CSS标记所选页面以获取以下代码:
<?php
$result = $DB_con->query('SELECT COUNT(*) FROM tbl_users');
$totalRecords = $result->fetchColumn();
$totalPages = max(1, ceil($totalRecords / $recordsPerPage));
for ($i=1; $i<=$totalPages; $i++) {
echo "<span class='navigations_items_span'>";
//if($page===$i) echo "<b>Visiting Page</b>";
echo "<b>Page </b>";
echo "<a href='index3.php?page=".$i."' class='navigation_item selected_navigation_item'>. ".$i.".</a>";
echo "</span>";
};
?>
我想放在一行:echo "<a href='index3.php?page=".$i."' class='navigation_item selected_navigation_item'>. ".$i.".</a>";
但每次都会收到错误,如果放在这里怎么样?
请帮忙。
答案 0 :(得分:0)
在for
循环中:
if($page == $i)
$class = 'navigation_item selected_navigation_item';
else
$class = '';
echo "<a href='index3.php?page=".$i."' class='".$class."'>. ".$i.".</a>";