Oleksii
Новичок
PHP:
<?php
require_once "db.php";
echo <<<HTML
<form action='post.php' method='post'>
<b>Name:</b><br>
<input type='text' name='name'><br>
<b>Message</b><br>
<textarea cols=50 rows=10 name='msg'></textarea><br><br>
<input type='submit' value='Send'><br><br><hr>
</form>
HTML;
$num = 10;
if(isset($_GET['page'])) $page = $_GET['page']-1;
else $page = 0;
$start = abs($page * $num);
$query = "SELECT * FROM messages LIMIT $start, $num";
$result = dbConnect()->query($query);
while($row = $result->fetch_array(MYSQLI_ASSOC))
{
echo "<b>" . $row['name'] . ":</b> " . $row['msg'] . "<br><br><hr>";
}
$count_query = "SELECT * FROM messages";
$count_result = dbConnect()->query($count_query);
$rows = $count_result->num_rows;
$num_pages = ceil($rows / $num);
for($i = 1; $i <= $num_pages; $i++)
{
if($i-1 == $page) echo $i . "\n.\n";
else echo "<a href='" . $_SERVER['PHP_SELF'] . "?page=" . $i . "'>\n" . $i . "\n.\n</a>";
}
$result->close();
$count_result->close();
dbClose();
?>