- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 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 и сортировать по дате, но выдаёт ошыбки...