Question of spatial navigation



  • There is a code:

    <?php  
    };  
    ?>
    
         &lt;?php  
         $sql = "SELECT COUNT(id) FROM news";  
         $rs_result = mysql_query($sql);  
         $row = mysql_fetch_row($rs_result);  
         $total_records = $row[0];
         $total_pages = ceil($total_records / $limit);  
         $pagLink = "&lt;nav&gt;&lt;ul class='pagination'&gt;";  
         for ($i=1; $i&lt;=$total_pages; $i++) {  
         $pagLink .= "&lt;li&gt;&lt;a href='news.php?page=".$i."'&gt;".$i."&lt;/a&gt;&lt;/li&gt;";  
    

    };
    echo $pagLink . "</ul></nav>";
    ?>

    Question: How do you add "active" to navigation?



  • Such a test would be more correct, since if the paragraph of the page is not transmitted, the page should still be the first.

    $page = ((int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
    if ($page == $i) echo 'class="active"';
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2