concatenation problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
etsted
Forum Newbie
Posts: 15
Joined: Thu Feb 06, 2014 12:33 pm

concatenation problems

Post 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;
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: concatenation problems

Post by social_experiment »

are you referring to this section?

Code: Select all

<?php
while($row = mysqli_fetch_array($query)) {
$title .= $row['title'] . "
";
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply