davinci Posted March 5, 2006 Share Posted March 5, 2006 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]<?phpinclude '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 pageif ($pageNum > 1){ $page = $pageNum - 1; $prev = " <a href=\"$self?page=$page\">[Prev]</a> "; $first = " <a href=\"$self?page=1\">[First Page]</a> ";} else{ $prev = ' '; // we're on page one, don't print previous link $first = ' '; // 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 = ' '; // we're on the last page, don't print next link $last = ' '; // nor the last page link}// print the navigation linkecho $first . $prev . $nav . $next . $last;?> [/code] Quote Link to comment Share on other sites More sharing options...
JasperBosch Posted March 5, 2006 Share Posted March 5, 2006 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] Quote Link to comment Share on other sites More sharing options...
davinci Posted March 5, 2006 Author Share Posted March 5, 2006 Got it now, thanks! Quote Link to comment Share on other sites More sharing options...
davinci Posted March 5, 2006 Author Share Posted March 5, 2006 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 Link to comment Share on other sites More sharing options...
davinci Posted March 7, 2006 Author Share Posted March 7, 2006 [!--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? Quote Link to comment Share on other sites More sharing options...
AndyB Posted March 7, 2006 Share Posted March 7, 2006 Put whatever page title you want [b]before[/b] the start of the while loop. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.