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

Link to comment
Share on other sites

you $recordnum = $limit => number of pages is 1

you must count all records without limit part

$recordnum = mysql_result(mysql_query("SELECT count(*) FROM `Tutorials` WHERE `Section`='".Secure($_GET['section'])."' AND `Approved`='1' "),0,0);

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.