Jump to content

Pagination question?


lct

Recommended Posts

Trying to do pagination with 2 variables.

 

http://www.chicago3media.com/new_site/cat_page_test.php

 

If you go there, click on one of the links to the left, then click on Newer Post (to the right of the images), it just goes blank. Now I know that is because the $catID is not being carried over when you try to go to the next page of videos. Stuck on this one, so any help would be appreciated.

 

<?php
require('connect.php');

function Category($catID){
$catNav = mysql_query("SELECT * FROM jos_hwdvidscategories WHERE id = '$catID'");
$catNav_arr = mysql_fetch_array($catNav);
$catRealID = $catNav_arr['id'];
$catName = $catNav_arr['category_name'];

echo '<div id="nav-wrap">';
echo '<a href="cat_page_test.php?' . $catID . '">';
echo $catName;
echo '</a>';
echo '</div>';

}

echo '<div id="main-wrap">';
echo '<div id="navbar-wrap">';
Category($catID = '16');
Category($catID = '3');
Category($catID = '14');
Category($catID = '15');
Category($catID = '5');
Category($catID = '6');
Category($catID = '7');
Category($catID = '9');
Category($catID = '10');
Category($catID = '11');
Category($catID = '12');
Category($catID = '19');

echo '</div>';

echo '<div id="fvm-wrap">';

if(isset($_GET['16'])){
	Display_Category($catID = '16');
}
else if(isset($_GET['3'])){
	Display_Category($catID = '3');
}
else if(isset($_GET['14'])){
	Display_Category($catID = '14');
}
else if(isset($_GET['15'])){
	Display_Category($catID = '15');
}
else if(isset($_GET['5'])){
	Display_Category($catID = '5');
}
else if(isset($_GET['6'])){
	Display_Category($catID = '6');
}
else if(isset($_GET['7'])){
	Display_Category($catID = '7');
}
else if(isset($_GET['9'])){
	Display_Category($catID = '9');
}
else if(isset($_GET['10'])){
	Display_Category($catID = '10');
}
else if(isset($_GET['11'])){
	Display_Category($catID = '11');
}
else if(isset($_GET['12'])){
	Display_Category($catID = '12');
}
else if(isset($_GET['19'])){
	Display_Category($catID = '19');
}

//============================================
function Display_Category($catID){
if (!(isset($pagenum))) 
{ 
$pagenum = 1; 
} 

//Here we count the number of results 
//Edit $data to be your query 
$data = mysql_query("SELECT * FROM jos_hwdvidsvideos WHERE category_id = '$catID' AND published = 1 ORDER BY id DESC") or die(mysql_error()); 
$rows = mysql_num_rows($data); 

//This is the number of results displayed per page 
$page_rows = 6; 

//This tells us the page number of our last page 
$last = ceil($rows/$page_rows); 

//this makes sure the page number isn't below one, or more than our maximum pages 
if ($pagenum < 1) 
{ 
$pagenum = 1; 
} 
elseif ($pagenum > $last) 
{ 
$pagenum = $last; 
} 

//This sets the range to display in our query 
$max = 'limit ' .($pagenum - 1) * $page_rows .',' .$page_rows;

  //This is your query again, the same one... the only difference is we add $max into it
$data_p = mysql_query("SELECT * FROM jos_hwdvidsvideos WHERE category_id = '$catID' AND published = 1 ORDER BY id DESC $max") or die(mysql_error()); 
//This is where you display your query results
	while($fetch_arr = mysql_fetch_array($data_p)){
		$fVideoID = $fetch_arr['video_id'];
		$fTitle = $fetch_arr['title'];
		$fViews = $fetch_arr['number_of_views'];
		$fID = $fetch_arr['id'];



		echo '<div id="fv-wrap">';

		echo '<div id="fv-thumb">';

			echo '<a href="http://www.chicago3media.com/video-categories.html?task=viewvideo&video_id=' . $fID . '">';

			echo '<img src="http://www.chicago3media.com/hwdvideos/thumbs/';
			echo $fVideoID;
			echo '.jpg" . width="128px" height="76px"  />';


			echo '</a>';

		echo '</div>';

		echo '<div id="fv-title">';


			if(strlen($fTitle) <= 24){
			echo '<a href="http://www.chicago3media.com/video-categories.html?task=viewvideo&video_id=' . $fID . '" . class="main-link">';
			echo $fTitle; 
			echo '</a>';
			}

			else{
				echo '<a href="http://www.chicago3media.com/video-categories.html?task=viewvideo&video_id=' . $fID . '" . class="main-link">';
				echo substr($fTitle, 0,25) . '...';
				echo '</a>';
			}

			echo '<div id="fv-views">';
			echo $fViews . ' views';
			echo '</div>';

		echo '</div>';

	echo '</div>'; 
	}

// First we check if we are on page one. If we are then we don't need a link to the previous page or the first page so we do nothing. If we aren't then we generate links to the first page, and to the previous page.
if ($pagenum == 1) 
{
} 
else 
{
$previous = $pagenum-1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$previous'>Older Post</a> ";
} 

//This does the same as above, only checking if we are on the last page, and then generating the Next and Last links
if ($pagenum == $last) 
{
} 
else {
$next = $pagenum+1;
echo " <a href='{$_SERVER['PHP_SELF']}?pagenum=$next'>Newer Post</a> ";
} 

  // This shows the user what page they are on, and the total number of pages
echo '<br />';
echo 'Page ' . $pagenum . ' of ' . $last;
}
?>

Link to comment
https://forums.phpfreaks.com/topic/208346-pagination-question/
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.