Page 1 of 1

concatenation problems

Posted: Fri Feb 07, 2014 1:08 pm
by etsted
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;

Re: concatenation problems

Posted: Sat Feb 08, 2014 2:06 pm
by social_experiment
are you referring to this section?

Code: Select all

<?php
while($row = mysqli_fetch_array($query)) {
$title .= $row['title'] . "
";
?>