Jump to content

Paging help


davinci

Recommended Posts

When no video is selected for video.php, the script lists all my videos with descriptions and playcounts in a column. Problem is when I try to add paging for some reason its only displaying one entry instead of five per page. The amount of pages is correct however it only shows one video per page instead of the correct page listing.

Can someone spot my error?

[code]

<?php

include 'library/config.php';
include 'library/opendb.php';

$id = $_GET['id'];

if ($id == "") {

$rowsPerPage = 5;
$pageNum = 1;
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}
$offset = ($pageNum - 1) * $rowsPerPage;

$query = "SELECT id, name, path, title, thumbnail, playcount, DATE_FORMAT(entry_date, '%M %D %Y') FROM upload2 ORDER BY id DESC LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');
while($row = mysql_fetch_array($result)) { ?>

<div align="center">

<table cellpadding="2" width="65%"  border="0" cellspacing="0" cellpadding="0"><tr>

<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><IMG BORDER="0" img src="media/thumbs/<?=$row['thumbnail'];?>" height="80" width="80"><p>

</a></td>
<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><b><?php echo $row['title'];?></b></a><br>Added on <?=$row['date'];?>
<br>Plays: <?=$row['playcount'];?>

</td></tr></table>
<?php

// how many rows we have in database
$query   = "SELECT COUNT(id) AS numrows FROM upload2";
$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
    if ($page == $pageNum)
    {
        $nav .= " $page ";   // no need to create a link to current page
    }
    else
    {
        $nav .= " <a href=\"$self?page=$page\">$page</a> ";
    }        
}

// creating previous and next link
// plus the link to go straight to
// the first and last page

if ($pageNum > 1)
{
    $page = $pageNum - 1;
    $prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
    
    $first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
    $prev  = '&nbsp;'; // we're on page one, don't print previous link
    $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
    $next = " <a href=\"$self?page=$page\">[Next]</a> ";
    
    $last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
    $next = '&nbsp;'; // we're on the last page, don't print next link
    $last = '&nbsp;'; // nor the last page link
}

// print the navigation link
echo $first . $prev . $nav . $next . $last;


?>
[/code]
Link to comment
https://forums.phpfreaks.com/topic/4159-paging-help/
Share on other sites

Hi,

On the way you lost the } from the while loop, that's the cause of showing just one video.

I think you don't want to declare a table for every video you dislplay. I rewrote a piece of your code:
[code]
...
$result = mysql_query($query) or die('Error, query failed'); ?>
<div align="center">

<table cellpadding="2" width="65%"  border="0" cellspacing="0" cellpadding="0">
<? while($row = mysql_fetch_array($result)) { ?>
<tr>

<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><IMG BORDER="0" img src="media/thumbs/<?=$row['thumbnail'];?>" height="80" width="80"><p>

</a></td>
<td width="50%">

<a href="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?= $row['id'];?>"><b><?php echo $row['title'];?></b></a><br>Added on <?=$row['date'];?>
<br>Plays: <?=$row['playcount'];?>

</td></tr>
<? } ?>
</table>
<?php

// how many rows we have in database
...
[/code]
Link to comment
https://forums.phpfreaks.com/topic/4159-paging-help/#findComment-14443
Share on other sites

[!--quoteo(post=351902:date=Mar 5 2006, 05:19 PM:name=davinci)--][div class=\'quotetop\']QUOTE(davinci @ Mar 5 2006, 05:19 PM) [snapback]351902[/snapback][/div][div class=\'quotemain\'][!--quotec--]
While we got this script posted, can someone tell me how to add a a text header to the top of this video listing page?

Whatever I try, it keeps repeating my chosen title name for every output in the listing.

Thanks!
[/quote]


Anyone?
Link to comment
https://forums.phpfreaks.com/topic/4159-paging-help/#findComment-14886
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.