Jump to content

concatenation


etsted
 Share

Recommended Posts

the thing whit this pagination script is that it works, but then thing is that it concatenates all of my "titles" into on link. But if i take away the concatenation then the pagination will only display one item from my database.

 

include "connect.php";
$count_query = mysqli_query($con, "SELECT NULL FROM videos");
$count = mysqli_num_rows($count_query);
if(isset($_GET['search'])) {
$page = preg_replace("#[^0-9]#","",$_GET['search']);
} else {
$page = 1;
}
$perPage = 2;
$lastPage = ceil($count/$perPage);
if($page < 1) {
$page = 1;
} else {
if($page > $lastPage) {
$page = $lastPage;
}
}
$limit = "LIMIT " . ($page - 1) * $perPage . ", $perPage";
$query = mysqli_query($con, "SELECT * FROM videos ORDER BY id DESC $limit");
if($lastPage != 1) {
if($page != 1) {
$prev = $page - 1;
$pagination .= '<a href="pagination.php?search='.$prev.'">Previous</a> ';
}
if($page != $lastPage) {
$next = $page + 1;
$pagination .= '<a href="pagination.php?search='.$next.'">Next</a>';
}
}
while($row = mysqli_fetch_array($query)) {
$title .= $row['title'] . "<br />";
$url .= $row['url'];
$description .= $row['description'] . "<br />";
}
echo "<h3><a href='$url'>$title</a><h3>
$description";
echo $pagination;
Link to comment
Share on other sites

It's doing exactly what you tell it to do. You have a loop where you loop through the database records. After that loop, you display one thing. It's doing exactly what you told it to do, you told it to only display the last record that it selected.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...