Jump to content

[SOLVED] Pagination problems.


xyn

Recommended Posts

Hey!

Basically This coding below isnt displaying errors but the

problem is I have 2 records within my database, to test

the script i wanted to display 1 record per page...

 

which means i would have 2 pages; Well this script shows

1 Records, 1 page. and thats it :S

 

<?php
include("../config.php");
ob_start();
session_start();

$dir = $_GET['section'];
$id  = $_GET['page_id'];
$pg  = $_GET['page'];
include("/home/ascripts/private_files/sql.inc.php");
include("../inc/headers/top.inc.php");
if(!$dir)
{	// Display the categories.
// In two columns.
include("home.php");
}
elseif(isset($dir) &&!isset($id))
{	// Display the specific tutorials for this section
// Page them 50 per page.
if((!$pg)||($pg == "0")) {
$pg = 1;
}
$limit    = 1;
$limitval = $pg * $limit - ($limit);

$sql_section = mysql_query("SELECT * 
FROM `Tutorials` 
WHERE `Section`='".Secure($_GET['section'])."' 
AND `Approved`='1' 
ORDER BY `tutorialid` ASC
LIMIT $limitval, $limit");

$recordnum= mysql_num_rows($sql_section);
if(!mysql_num_rows($sql_section))
{	// No records; no tutorials here.
	echo('no records!');
	$nav = "hide";
}
else
{	//records found; display them.
	while($section = mysql_fetch_array($sql_section))
	{
		//display the tutorials
	}
}
if($pg == "1") {
	$previous = "[ Previous";
}else{
	$pgpast = $pg-1;
	$previous = "[ <a href=\"/tutorials/index.php?section=$dir\">Previous</a>";
}

$totalrecords = floor($recordnum / $limit);
for($i=0; $i<=$recordnum; $i++)
{
	if($i == "0")
	{
		$pages.= "";
	}
	elseif($i == $pg)
	{
		$pages.= " | $i";
	}
	else
	{
		$pages.= " | <a href=\"/tutorials/index.php?section=$dir&page=$i\">$i</a>";
	}
}

if(($recordnum - ($limit * $pg)) >0)
{
	$pgnext = $pg+1;
	$next = " | <a href=\"/tutorials/index.php?section=$dir&page=$pgnext\">Next</a> ]";
}
else
{
	$next = " | Next ]";
}

if($nav != "hide") {
	echo("<p align=\"center\">" . $previous . $pages . $next . "</p>");
}
}
elseif(isset($dir) &&isset($id))
{	// Now lets display the tutorial.
echo("Tutorial display: ".$id);
}
else
{
include("../404.php");
}
include("../inc/headers/bottom.inc.php");
ob_end_flush();
?>

Link to comment
https://forums.phpfreaks.com/topic/58434-solved-pagination-problems/
Share on other sites

Ok, the problem is here...

 

$totalrecords = floor($recordnum / $limit);
for($i=0; $i<=$totalrecords; $i++)
{
	if($i == "0")
	{
		$pages.= "";
	}
	elseif($i == $pg)
	{
		$pages.= " | $i";
	}
	else
	{
		$pages.= " | <a href=\"/tutorials/index.php?section=$dir&page=$i\">$i</a>";
	}
}

 

I'm lsot for ideas though :S

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.