"PHP" / Говнокод #25551 Ссылка на оригинал

0

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 62
  63. 63
  64. 64
  65. 65
  66. 66
  67. 67
  68. 68
  69. 69
  70. 70
  71. 71
  72. 72
  73. 73
  74. 74
  75. 75
  76. 76
  77. 77
  78. 78
<?php $connection = mysqli_connect ('localhost','root','','userlistdb'); 
       
        $per_page = 25;
        $page = 1;

if (isset($_GET['page']))
        {
    $page = (int) $_GET['page'];
}
        $total_cout_q = mysqli_query($connection, "SELECT COUNT(id_com) AS `total_count` FROM `comment`")
        $total_count = mysqli_fetch_assoc($total_cout_q);
        $total_count = $total_count['total_count'];
        
        $total_pages = ceil ($total_count/ $per_pages);
        if($page <= 1 || $page > $total_pages)
        {
            $page = 1;
        }
        $offset = ($per_page * $page)- $per_page;
        $coments = mysqli_query($connection, "SELECT *  `total_count` FROM `comment` ORDER  BY `id_com` DESC LIMIT  $offset, $per_page"); 
       $coments_exist = true;
        if(mysqli_nu,_rows($coments) <= 0 ){
           echo 'Нет коментариев';
            $coments_exist = false;
       }
    while( $result = mysqli_fetch_assoc($coments){
            
        } 
        $row = mysqli_query($connection, "SELECT * FROM `comment` ORDER  BY `id_com` DESC LIMIT 25");      
    ?>

     <table>
    <tr>
        <th><a href="?orderBy=username">username:</a>
        </th>
        <th>  <a href="?orderBy=email">email:</a>
        </th>
        <th>  <a href="?orderBy=recorded_date"> Date:</a>
        </th>
        <th>  <a href="?orderBy=comment">Added Date:</a>
        </th>
    </tr>
    
         <?php 
            while($row = mysql_fetch_array($result)){
    ?>
      <tr>
       <th><?php echo $result['username']; ?> </th>
       <th><?php echo $result['email']; ?> </th>
       <th><?php echo $result['Date']; ?> </th>
       <th><?php echo $result['comment']; ?> </th>
       </tr>
     </table>

<?php //Страницы 
                if ( $coments_exist = true)
                {
                    echo '<div class="paginator">';
                if($page > 1)
                    {
                echo '<a href= "/Guestbook.php?page='.($page - 1).'">« предыдущий </a>'; 
                }  if($page < $total_pages)
                    {
                echo '<a href= "/Guestbook.php?page='.($page + 1).'"> Cледующая &eaquo; </a>';        
                }
                    echo '</div>';
                }
                
                $orderBy = array('username', 'email', 'recorded_date', 'comment');

$order = 'username';
if (isset($_GET['orderBy']) && in_array($_GET['orderBy'], $orderBy)) {
    $order = $_GET['orderBy'];
      }
         $query = 'SELECT * FROM `comment` ORDER BY '.$order;
     }
mysqli_close();
?>

Привет, тут в коде сортировка и переход по страницыам, сортировка в строки с таблицы HTML, вызываемые из MySQL, при нажиматие на username едёт сортировка по алфавиту, а затем нажимать на email или Date и сортировать по дате, но выдаёт ошыбки...

Запостил: arts arts, (Updated )

Комментарии (3) RSS

  • ошибки - это плохо. ошибки надо исправлять.
    Ответить
    • «Исправлять ошибки» — это не «PHP-way». В «PHP» для этого есть «собака», «error_reporting(0)» и «@ini_set('display_errors', 0)».
      Ответить

Добавить комментарий

Где здесь C++, guest?!

    А не использовать ли нам bbcode?


    8