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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.