Jump to content


Photo

Paging help


  • Please log in to reply
5 replies to this topic

#1 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 05 March 2006 - 07:44 PM

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?


<?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;


?> 


#2 JasperBosch

JasperBosch
  • New Members
  • Pip
  • Newbie
  • 8 posts
  • LocationApeldoorn, The Netherlands

Posted 05 March 2006 - 08:29 PM

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:
...
$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
...


#3 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 05 March 2006 - 09:16 PM

Got it now, thanks!

#4 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 05 March 2006 - 10:19 PM

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!

#5 davinci

davinci
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 07 March 2006 - 12:34 AM

[!--quoteo(post=351902:date=Mar 5 2006, 05:19 PM:name=davinci)--][div class=\'quotetop\']QUOTE(davinci @ Mar 5 2006, 05:19 PM) View Post[/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?

#6 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 07 March 2006 - 12:55 AM

Put whatever page title you want before the start of the while loop.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users