PageRenderTime 45ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/category.php

https://gitlab.com/nezam.technovista/news-project-php
PHP | 103 lines | 97 code | 6 blank | 0 comment | 13 complexity | 780382704e46cd00ee08e6bf0c682ab6 MD5 | raw file
  1. <?php include 'header.php'; ?>
  2. <div id="main-content">
  3. <div class="container">
  4. <div class="row">
  5. <div class="col-md-8">
  6. <!-- post-container -->
  7. <div class="post-container">
  8. <?
  9. include "config.php";
  10. if (isset($_GET["cid"])) {
  11. $category_id = $_GET["cid"];
  12. }
  13. $sql2 = "SELECT * FROM category WHERE category_id = {$category_id}";
  14. $query2 = mysqli_query($conn, $sql2) or die("Query faild");
  15. $row2 = mysqli_fetch_assoc($query2);
  16. ?>
  17. <h2 class="page-heading"><?php echo $row2["category_name"] ?></h2>
  18. <?php
  19. $limit = 3;
  20. if (isset($_GET["pageId"])) {
  21. $page = $_GET["pageId"];
  22. } else {
  23. $page = 1;
  24. }
  25. $offset = ($page - 1) * $limit;
  26. $sql1 = "SELECT post.post_id, post.title, post.description, post.post_date, post.category, post.post_img, post.author, category.category_name, user.user_name FROM post
  27. LEFT JOIN category ON post.category = category.category_id
  28. LEFT JOIN user ON post.author = user.user_id
  29. WHERE post.category={$category_id}
  30. ORDER BY post.post_id DESC LIMIT {$offset}, {$limit}";
  31. $query1 = mysqli_query($conn, $sql1) or die("Query Faild");
  32. if (mysqli_num_rows($query1) > 0) {
  33. while ($row = mysqli_fetch_assoc($query1)) {
  34. ?>
  35. <div class="post-content">
  36. <div class="row">
  37. <div class="col-md-4">
  38. <a class="post-img" href="single.php?id=<?php echo $row["post_id"]; ?>"><img src="admin/upload/<?php echo $row["post_img"]; ?>" alt="" /></a>
  39. </div>
  40. <div class="col-md-8">
  41. <div class="inner-content clearfix">
  42. <h3><a href='single.php?id=<?php echo $row["post_id"]; ?>'><?php echo $row["title"]; ?></a></h3>
  43. <div class="post-information">
  44. <span>
  45. <i class="fa fa-tags" aria-hidden="true"></i>
  46. <a href='category.php'><?php echo $row["category_name"]; ?></a>
  47. </span>
  48. <span>
  49. <i class="fa fa-user" aria-hidden="true"></i>
  50. <a href='author.php?aid=<?php echo $row["author"]; ?>'><?php echo $row["user_name"]; ?></a>
  51. </span>
  52. <span>
  53. <i class="fa fa-calendar" aria-hidden="true"></i>
  54. <?php echo $row["post_date"]; ?>
  55. </span>
  56. </div>
  57. <p class="description">
  58. <?php echo substr($row["description"], 0, 2) . "..."; ?>
  59. </p>
  60. <a class='read-more pull-right' href='single.php?id=<?php echo $row["post_id"]; ?>'>read more</a>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65. <?php
  66. }
  67. } else {
  68. echo "<h2>No record Found...</h2>";
  69. }
  70. if (mysqli_num_rows($query2) > 0) {
  71. $total_records = $row2["post"];
  72. $total_pages = ceil($total_records / $limit);
  73. echo "<ul class='pagination admin-pagination'>";
  74. if ($page > 1) {
  75. echo "<li><a href='index.php?cid=" . $category_id . "&pageId=" . ($page - 1) . "'>Prev</a></li>";
  76. }
  77. for ($i = 1; $i <= $total_pages; $i++) {
  78. if ($i == $page) {
  79. $active = "active";
  80. } else {
  81. $active = "";
  82. }
  83. echo "<li class='" . $active . "'><a href='index.php?cid=" . $category_id . "&pageId=$i'>" . "$i" . "</a></li>";
  84. }
  85. if ($total_pages > $page) {
  86. echo "<li><a href='index.php?cid=" . $category_id . "&pageId=" . ($page + 1) . "'>Next</a></li>";
  87. }
  88. echo "</ul>";
  89. }
  90. ?>
  91. </div><!-- /post-container -->
  92. </div>
  93. <?php include 'sidebar.php'; ?>
  94. </div>
  95. </div>
  96. </div>
  97. <?php include 'footer.php'; ?>