Jump to content

paging with a content manager


aznjayx

Recommended Posts

I'm currently working on the webiste and used the code to switch the website to go to a < table > content section, the first page of the mysql that is taken out shows out but with pagination it doesn't work at all.

 

for example there is a link index.php?page=news

and when you click on the link the link doesn't function and gives an error

and when i click page 1,2,3 the link doesn't go news?=1

 

<?php

$file = $_GET['page'].'.php';

if (file_exists($file)) {

include $file;

 

 

} elseif ($_GET['page'] == '') {

 

 

include "test.php";

 

 

} else {

 

 

echo "404 ERROR WE COOL";

 

 

}

?>

</td>

<td class="other">

<font color="white">

<?php

$file = $_GET['id'].'.php';

if (file_exists($file)) {

include $file;

 

 

} elseif ($_GET['page'] == '') {

 

 

include "home.php";

 

 

} else {

 

 

echo "404 ERROR WE COOL";

 

 

}

?>

 

this code works if i'm only running files that are in that are upload and doesn't load the data from sql since i have pagination in newsfeed.php, when i click on next it doesn't load the date from the mysql

Link to comment
Share on other sites

idk if this will help but I use the following code for pagination...

 

/pagination section 1 start

	// the if below, states that if the variable in the URL named page has a value, $start will be set to it, 
	// otherwise by default it is set to 0, meaning that it will start at the beginning of the table by default.

	$limit = 5;

	if (!$_GET['start']){
		$start = 0;
	} else {
		$start = $_GET['start'];
	}

	// this if below checks that the start variable isn’t negative, because if it is, our script will screw up. 
	// If it finds that it is, it redirects to the default page where the start is 0.

// pagination section 1 end

// Select all information from the comments table
$sql = "SELECT * FROM $table WHERE channel = '$channel' ORDER BY date DESC LIMIT $start, $limit";

   //create list of results
$result = @mysql_query($sql,$connection) or die(mysql_error());	


// pagination part 2 start
// the set of statements below displays the previous and next page links

	$next = $start + $limit;
	$previous = $start - $limit;

	if ($previous < 0) {
		// do not display previous
	} else {
		echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$previous\"><< Previous</a>";
		if ($num_rows == 5) {
			echo "&nbsp&nbsp--&nbsp&nbsp";
		}
	}
	// numbers rows to display next link
	$num_rows = mysql_num_rows($result);
	if ($num_rows < 5) {
   // do not display next link	
	} else {
		echo "<a href=\"".$_SERVER['PHP_SELF']."?start=$next\">Next >></a>";
	}


// pagination part 2 end

 

if you need help understanding it.. pm me or IM me on AIM... user name here is same on AIM...

 

Q

Link to comment
Share on other sites

Your page url variable gets in 1,2 etc as value, but in the code u have:

 

$file = $_GET['page'].'.php';
if (file_exists($file)) {
include $file;

 

Are u including files 1.php, 2.php etc, or is it me not understanding this.

Link to comment
Share on other sites

this is my paging script

 

 

 

// how many rows to show per page

$rowsPerPage = 3;

 

// by default we show first page

$pageNum = 1;

 

// if $_GET['page'] defined, use it as page number

if(isset($_GET['page']))

{

$pageNum = $_GET['page'];

}

 

// counting the offset

$offset = ($pageNum - 1) * $rowsPerPage;

 

 

echo '<table width="400" border="0" cellspacing="0" cellpadding="0">';

$query  = "SELECT * FROM news LIMIT $offset, $rowsPerPage";

$result = mysql_query($query) or die('Error, query failed');

$color="1";

// print the random numbers

while($row = mysql_fetch_array($result)){

 

if($color==1){

echo '<tr>

<td class="beam">'.$row['date'].' '.$row['time'].' '.$row['name'].'<br>'.$row['msg'].'</td></tr>';

// Set $color==2, for switching to other color

$color="2";

}

 

// When $color not equal 1, use this table row color

else {

echo '<tr>

<td class="beamer">'.$row['date'].' '.$row['time'].'  '.$row['name'].'<br>'.$row['msg'].'</td></tr>';

// Set $color back to 1

$color="1";

}

}

 

echo '<br>';

echo '</table>';

 

// how many rows we have in database

$query  = "SELECT COUNT(id) AS numrows FROM news";

$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  = ' '; // 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 link

echo $first . $prev . $nav . $next . $last;

?>

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.