hello me again:)
There is a page in my cms that users can see my posts there and i want to limit the number of posts that must be shown to users in each page and paginate.
This is my code:
<?php
$servername = "localhost";
$dbname = "mydbname";
$dbusername = "mydbusername";
$dbpassword = "mydbpassword";
try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $dbusername, $dbpassword);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$number = "";
if(isset($_POST['submit'])) {
$sql = "SELECT ID, Title, Author, Content FROM Posts LIMIT" . $_POST['number'] . ", 3";
$result = $conn->query($sql);
foreach($result as $row) {
echo $row['ID'] . ") ";
echo "<a href='single-post-page.php?post=" . $row['ID'] . "'>" . $row['Title'] . "</a>";
echo "<br>" . " by: " . $row['Author'];
echo "<br>";
echo $row['Content'];
echo "<br><br><br>";
}
}
} catch(PDOException $e) {
echo $sql . "<br>" . $e->getMessage();
}
$conn = null;
?>
<html>
<head>
<title>User View Page</title>
</head>
<body>
<hr>
<form method="post">
<input type="text" name="number">
<input type="submit" value="Submit">
</form>
</body>
</html>
How the script can take the value i send after clicking the submit button, to LIMIT x, y
part?
My code above doesn't work, i face with a page with an input form and a submit button, and when i type a number and click the submit button, nothing happens.