0

Ok, so I have tried probably 5 different pagination tutorials online and none of them are working out for me. So I am stuck on this last tutorial and cannot get it to work. So I am hoping someone on here can help me out.

First I have an include file paginator.cass.php, I have read through the tutorial and I dont know if i am supposed to add anything to the file.

<?php

class Paginator{
	var $items_per_page;
	var $items_total;
	var $current_page;
	var $num_pages;
	var $mid_range;
	var $low;
	var $high;
	var $limit;
	var $return;
	var $default_ipp = 25;
	var $querystring;

	function Paginator()
	{
		$this->current_page = 1;
		$this->mid_range = 7;
		$this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
	}

	function paginate()
	{
		if($_GET['ipp'] == 'All')
		{
			$this->num_pages = ceil($this->items_total/$this->default_ipp);
			$this->items_per_page = $this->default_ipp;
		}
		else
		{
			if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
			$this->num_pages = ceil($this->items_total/$this->items_per_page);
		}
		$this->current_page = (int) $_GET['page']; // must be numeric > 0
		if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
		if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
		$prev_page = $this->current_page-1;
		$next_page = $this->current_page+1;

		if($_GET)
		{
			$args = explode("&",$_SERVER['QUERY_STRING']);
			foreach($args as $arg)
			{
				$keyval = explode("=",$arg);
				if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
			}
		}

		if($_POST)
		{
			foreach($_POST as $key=>$val)
			{
				if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
			}
		}

		if($this->num_pages > 10)
		{
			$this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">&laquo; Previous</a> ":"<span class=\"inactive\" href=\"#\">&laquo; Previous</span> ";

			$this->start_range = $this->current_page - floor($this->mid_range/2);
			$this->end_range = $this->current_page + floor($this->mid_range/2);

			if($this->start_range <= 0)
			{
				$this->end_range += abs($this->start_range)+1;
				$this->start_range = 1;
			}
			if($this->end_range > $this->num_pages)
			{
				$this->start_range -= $this->end_range-$this->num_pages;
				$this->end_range = $this->num_pages;
			}
			$this->range = range($this->start_range,$this->end_range);

			for($i=1;$i<=$this->num_pages;$i++)
			{
				if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
				// loop through all pages. if first, last, or in range, display
				if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
				{
					$this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
				}
				if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
			}
			$this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next &raquo;</a>\n":"<span class=\"inactive\" href=\"#\">&raquo; Next</span>\n";
			$this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
		}
		else
		{
			for($i=1;$i<=$this->num_pages;$i++)
			{
				$this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
			}
			$this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
		}
		$this->low = ($this->current_page-1) * $this->items_per_page;
		$this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
		$this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
	}

	function display_items_per_page()
	{
		$items = '';
		$ipp_array = array(10,25,50,100,'All');
		foreach($ipp_array as $ipp_opt)	$items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
		return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
	}

	function display_jump_menu()
	{
		for($i=1;$i<=$this->num_pages;$i++)
		{
			$option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
		}
		return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
	}

	function display_pages()
	{
		return $this->return;
	}
}

Then I have my file, which worked fine before I tried to add the pagination. So I know I am doing something wrong with the code.

Here is my entire file

<?php
//db connector
...


echo "<script type='text/javascript' src='http://....com/includes/jscript/rightclick.js'></script>";

// create an array to set page-level variables
$page = array();
$page['title'] = '... - "Motocross, Desert, and BMX" ';
$aid = mysql_real_escape_string($_GET['aid'], $con);
// include the page header
include('includes/template/header2.php');


//page starts here
echo "<div class='commentWrap'>";

echo "<table cellpadding='0' cellspacing='0'><tr><td>";

$select1 = ("SELECT * FROM photo_album WHERE aid = '$aid' ");
$result1 = mysql_query($select1) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
	echo "<h3 align='left'>".$row['title']."</h3>"
         ."<p align='left'>".$row['description']."</p>";
}

//Paginator include and objects
require_once('includes/pagination/paginator.class.php');
$pages = new Paginator;
$pages->items_total = $num_rows[0];
$pages->mid_range = 9;
$pages->paginate();


//gallery thumbs
$select = ("SELECT * FROM pictures WHERE aid = '$aid' ORDER BY pid ASC '$pages'->limit");
$result = mysql_query($select) or die(mysql_error());



echo "<div class='photoWrap'>";

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

echo "<div class='photoThumb'>"
   ."<a href='".$row['path']."'rel='lightbox[".$aid."]'>"
   //."<a href='".$filename."'>"
   ."<img border='0' width='150px' src='".$row['path']."' />"
   //."<img src='".$filename."' rel='lightbox['".$aid."']' border='0' width='100px' />"
   ."</a></div>";
}
echo "</div>";

//paginator pages
echo $pages->display_pages();


echo "</div></div>";
echo "</td><tr></table>";
mysql_close($con);
// include the page footer
include('includes/template/footer.php');
?>

So I am getting nothing, By the way this is a photo gallery.
Tutorial: http://net.tutsplus.com/tutorials/php/how-to-paginate-data-with-php/

Thanks for the help!

2
Contributors
22
Replies
26
Views
7 Years
Discussion Span
Last Post by bjeffries
0

Is it soo very important to write it as a class? Maybe u can make it simple on yourself first cos somehow u are now learning it. I can help u with a basic pagination that just work fine. But for me to get my head around all this bulky code, its kinda a job. Well, that's jus my view.

0

I dont need a crazy pagination. The most pages in one gallery will probably be 3. I just dont know how to set it up where you can simply click next page. This was the easiest most explained tutorial I found.

0

I think I can help u with that.
Well you have to dive the whole of this into 3:
>> You are going to need a link for Previous
>> A link for any other page
>> And a link for the next page
So now, let's get down to the code;

<?php
//include conn.php
//You are going to execute two queries on the db u are using
//the first one will count the total rows in ur table
$countQuery = "select count(*) as totalRows from <tablename>";
$countResult = mysql_query($countQuery);
$countData = mysql_fetch_array($countResult);
//Now you can calculate the total no. of pages to spread ur out ur data
$perPage = 10; //Number of records to display per page.
$totalPages = ($countData['totalRows']/perPage);

if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1; //default page
}
/*The above conditional stmts checks whether the page id is set and if its not, it sets it to page 1*/

$offset = ($page-1)*perPage //determines no. of records to skip each time
//With these out of the way, we begin setting our links
if($page>1){
$prev = $page-1 //I guess its self explanatory
echo "<a href=\"$_SERVER['PHP_SELF']?page=$prev\"> <<Prev </a>";
} 
for($i=1; $i<=$totalPages; $i++){
  if($page == $i){
    echo "<strong>$i</strong> // the current page does not need to be a link
   }
  else{
   echo "<a href=\"$_SERVER['PHP_SELF']?page=$i\">$i</a>;
  }
}
  if ($page != $totalPages){
   $next = $page+1;
   echo "<a href=\"SERVER['PHP_SELF']?page=$next\"> Next>></a>;
  }
// Now let's get the actual data from the DB
$sql = "select * from <tablename> limit $offset, $perPage";
$query = mysql_query($sql);
    //Lets loop through the result set
  while($row = mysql_fetch_array($query){
   // echo whatever you want out of the database;
   //eg. echo "<li>{$row['name']}</li>";
  }
?>

I guess this would do, whatever happens, I will be here. I don't know but there might be errors, I have not run it. I jus typed it outta here so careful, take your time and happy scripting.

0

I think I can help u with that.
Well you have to dive the whole of this into 3:
>> You are going to need a link for Previous
>> A link for any other page
>> And a link for the next page
So now, let's get down to the code;

<?php
//include conn.php
//You are going to execute two queries on the db u are using
//the first one will count the total rows in ur table
$countQuery = "select count(*) as totalRows from <tablename>";
$countResult = mysql_query($countQuery);
$countData = mysql_fetch_array($countResult);
//Now you can calculate the total no. of pages to spread ur out ur data
$perPage = 10; //Number of records to display per page.
$totalPages = ($countData['totalRows']/perPage);

if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1; //default page
}
/*The above conditional stmts checks whether the page id is set and if its not, it sets it to page 1*/

$offset = ($page-1)*perPage //determines no. of records to skip each time
//With these out of the way, we begin setting our links
if($page>1){
$prev = $page-1 //I guess its self explanatory
echo "<a href=\"$_SERVER['PHP_SELF']?page=$prev\"> <<Prev </a>";
} 
for($i=1; $i<=$totalPages; $i++){
  if($page == $i){
    echo "<strong>$i</strong> // the current page does not need to be a link
   }
  else{
   echo "<a href=\"$_SERVER['PHP_SELF']?page=$i\">$i</a>;
  }
}
  if ($page != $totalPages){
   $next = $page+1;
   echo "<a href=\"SERVER['PHP_SELF']?page=$next\"> Next>></a>;
  }
// Now let's get the actual data from the DB
$sql = "select * from <tablename> limit $offset, $perPage";
$query = mysql_query($sql);
    //Lets loop through the result set
  while($row = mysql_fetch_array($query){
   // echo whatever you want out of the database;
   //eg. echo "<li>{$row['name']}</li>";
  }
?>

I guess this would do, whatever happens, I will be here. I don't know but there might be errors, I have not run it. I jus typed it outta here so careful, take your time and happy scripting.

0

When I entered everything I get a blank page. Here is my code:

<?php
//db connector

echo "<script type='text/javascript' src='http://...com/includes/jscript/rightclick.js'></script>";

// create an array to set page-level variables
$page = array();
$page['title'] = ' - "Motocross, Desert, and BMX" ';
$aid = mysql_real_escape_string($_GET['aid'], $con);
// include the page header
include('includes/template/header2.php');


//page starts here
echo "<div class='commentWrap'>";

echo "<table cellpadding='0' cellspacing='0'><tr><td>";


$select1 = ("SELECT * FROM photo_album WHERE aid = '$aid' ");
$result1 = mysql_query($select1) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
	echo "<h3 align='left'>".$row['title']."</h3>"
         ."<p align='left'>".$row['description']."</p>";
}

//You are going to execute two queries on the db u are using
//the first one will count the total rows in ur table
$countQuery = "select count(*) as totalRows FROM pictures WHERE aid = '$aid'";
$countResult = mysql_query($countQuery);
$countData = mysql_fetch_array($countResult);
//Now you can calculate the total no. of pages to spread ur out ur data
$perPage = 10; //Number of records to display per page.
$totalPages = ($countData['totalRows']/perPage);

if(isset($_GET['page'])){
$page = $_GET['page'];
}
else{
$page = 1; //default page
}
/*The above conditional stmts checks whether the page id is set and if its not, it sets it to page 1*/

$offset = ($page-1)*perPage //determines no. of records to skip each time
//With these out of the way, we begin setting our links
if($page>1){
$prev = $page-1 //I guess its self explanatory
echo "<a href=\'"$_SERVER['PHP_SELF']"?page=$prev\'> <<Prev </a>";
} 
for($i=1; $i<=$totalPages; $i++){
  if($page == $i){
    echo "<strong>$i</strong>"; // the current page does not need to be a link
   }
  else{
   echo "<a href=\'"$_SERVER['PHP_SELF']"?page=$i\'>$i</a>";
  }
}
  if ($page != $totalPages){
   $next = $page+1;
   echo "<a href=\'"SERVER['PHP_SELF']"?page=$next\'> Next>></a>";
  }
// Now let's get the actual data from the DB
$sql = "select * from FROM pictures WHERE aid = '$aid' ORDER BY pid ASC limit $offset, $perPage";
$query = mysql_query($sql);
    //Lets loop through the result set
  while($row = mysql_fetch_array($query){
   // echo whatever you want out of the database;
   //eg. echo "<li>{$row['name']}</li>";
      ."<a href='".$row['path']."'rel='lightbox[".$aid."]'>"
   //."<a href='".$filename."'>"
   ."<img border='0' width='150px' src='".$row['path']."' />"
   //."<img src='".$filename."' rel='lightbox['".$aid."']' border='0' width='100px' />"
   ."</a></div>";
  }
  
  
echo "</div></div>";
echo "</td><tr></table>";
mysql_close($con);
// include the page footer
include('includes/template/footer.php');
  
?>

I did a little modifying to a few " that I saw were missing. But I do get a blank page.

0

check line 29, $aid is not a string, take out the quotes and lets see like

aid=$aid
0

Still nothing..
According to dreamweaver There are errors on these lines:
46:

if($page>1){

48:

echo "<a href=\'"$_SERVER['PHP_SELF']"?page=$prev\'> <<Prev </a>";

55:

echo "<a href=\'"$_SERVER['PHP_SELF']"?page=$i\'>$i</a>";

60:

echo "<a href=\'"SERVER['PHP_SELF']"?page=$next\'> Next>></a>";

66:

while($row = mysql_fetch_array($query){

I dont know if that will make the page not load but thats what the program is telling me..

Thanks for your help.

0

of course, a links should be

echo "<a href=\"<?php echo $_SERVER['PHP_SELF']?page=$prev\"> <<Prev </a>
//Do the same for next and the other but don't add additional quotes as u did before
//if the global array ($_SERVER) doesn't work, change it to the filename
0

Still nothing..

Why am I adding <?php echo to an already opened php snippet? and why would I not close it?

0

34.

$totalPages = ceil($countData['totalRows']/perPage);
echo " <a href='{$_SERVER['PHP_SELF']}?page=$prev'> <Prev </a> ";//48,55,60
0

if it still does not work, try a refined one. This works fine for me.

<?php
// database connection info
$db = 'vya';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect('localhost',$dbuser,$dbpass) or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db($db,$conn) or trigger_error("SQL", E_USER_ERROR);

// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM members";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
$sql = "SELECT * FROM members LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
   // echo data
   echo $list['memberID'] . " : " . $list['firstname']." ".$list['lastname'] . "<br />";
} // end while

/******  build the pagination links ****/
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
0

if it still does not work, try a refined one. This works fine for me.

<?php
// database connection info
$db = 'vya';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect('localhost',$dbuser,$dbpass) or trigger_error("SQL", E_USER_ERROR);
$db = mysql_select_db($db,$conn) or trigger_error("SQL", E_USER_ERROR);

// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM members";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
$sql = "SELECT * FROM members LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
   // echo data
   echo $list['memberID'] . " : " . $list['firstname']." ".$list['lastname'] . "<br />";
} // end while

/******  build the pagination links ****/
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/
?>
0

Alright, I am still getting a blank page. i mean literally blank. I'm not getting my header and the source only shows <html><head></head><body></body></HTML>

Dream Weaver is giving me 3 errors:

//line46
if($page>1){
//line48
echo "<a href=' {$_SERVER['PHP_SELF']}?page=$prev\'> <<Prev </a>";
//line66
  while($row = mysql_fetch_array($query){
0

ok so everything loads up to my gallery title:

from:

<?php
//db connector


// create an array to set page-level variables
$page = array();
$page['title'] = ' - "Motocross, Desert, and BMX" ';
$aid = mysql_real_escape_string($_GET['aid'], $con);
// include the page header
include('includes/template/header2.php');


//page starts here
echo "<div class='commentWrap'>";

echo "<table cellpadding='0' cellspacing='0'><tr><td>";
//echo "<div class='commentHead'>MotoDude Photo's</div>";

$select1 = ("SELECT * FROM photo_album WHERE aid = $aid ");
$result1 = mysql_query($select1) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
	echo "<h3 align='left'>".$row['title']."</h3>"
         ."<p align='left'>".$row['description']."</p>";
}

There is an issue somewhere in here. Doesnt display in my source code:

// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM pictures WHERE aid = $aid";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 10;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

// get the info from the db 
$sql = "SELECT * FROM pictures WHERE aid = $aid ORDER BY pid ASC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

echo "<div class='photoWrap'>";

// while there are rows to be fetched...
while ($list = mysql_fetch_assoc($result)) {
   echo "<div class='photoThumb'>"
   ."<a href='".$row['path']."'rel='lightbox[".$aid."]'>"
   //."<a href='".$filename."'>"
   ."<img border='0' width='150px' src='".$row['path']."' />"
   //."<img src='".$filename."' rel='lightbox['".$aid."']' border='0' width='100px' />"
   ."</a></div>";
} // end while

echo "</div>";

/******  build the pagination links ****/
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/

  
  
echo "</div></div>";
echo "</td><tr></table>";
mysql_close($con);
// include the page footer
include('includes/template/footer.php');
  
?>

So I am stumped on how to fix this..

0

Unfortunately, Dreamweaver doesn't display any arrors. so i do not know where to go from here..

0

don't be soo dependent on Dreamweaver in-built browser. Go ahead and use a real browser. Firefox preferrably.

0

I do use FireFox. I just use Dreamweaver to code. I dont even have a local server I upload everything to my webhost after I code everything.

0

Well I will suggest that u download WAMP or maybe XAMPP to make it easy on yourself. For all u know, u have some setting turned off on ur live server. Play around with ur code on your local machine and when everything works u upload. So if ur breaks down on the live server, u would know, its not from ur side, perhaps.

0

Sorry, its been a few days.. Great, another local server. I hate those things. What if I tried it on another live server? I have had bad luck with those local servers. I will try this on a different live server and see what I get.. If that fails then I will set up a local server.

Edited by bjeffries: n/a

0

ok So I tried this on another server and I still have no luck. Same exact code, same database setup, different photos. I get all the way to the title and description and nothing else after that.

Still no suggestions?
Here is my code again:

<?php
//db connector
$aid = mysql_real_escape_string($_GET['aid'], $con);
// create an array to set page-level variables
$page = array();
$page['title'] = '';
/* once the file is imported, the variables set above will become available to it */

// include the page header
include('includes/template/header.php');
//$aid = '1';

//page starts here
echo "<div align='center'>";
echo "<div class='wrapper_photo'>";
//Title and description
$select1 = ("SELECT * FROM photo_albums WHERE aid = '$aid' ");
$result1 = mysql_query($select1) or die(mysql_error());
while($row = mysql_fetch_array($result1)) {
	echo "<h3 align='left'>".$row['atitle']."</h3>"
         ."<p align='left'>".$row['description']."</p>";
}

// find out how many rows are in the table 
$sql = "SELECT COUNT(*) FROM pictures WHERE aid = $aid";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 2;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);

// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
   // cast var as int
   $currentpage = (int) $_GET['currentpage'];
} else {
   // default page num
   $currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
   // set current page to last page
   $currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < 1) {
   // set current page to first page
   $currentpage = 1;
} // end if

// the offset of the list, based on current page 
$offset = ($currentpage - 1) * $rowsperpage;

$sql = "SELECT * FROM pictures WHERE aid = $aid ORDER BY pid ASC LIMIT $offset, $rowsperpage";
$result = mysql_query($sql, $conn) or trigger_error("SQL", E_USER_ERROR);

//gallery thumbs
//$select = ("SELECT * FROM pictures WHERE aid = '$aid' ORDER BY pid ASC ");
//$result = mysql_query($select) or die(mysql_error());

echo "<div class='photoWrap'>";

while ($list = mysql_fetch_assoc($result)) {

echo "<div class='photoThumb'>"
   ."<a href='".$row['filepath'].$row['filename']."'rel='lightbox[".$aid."]'>"
   //."<a href='".$filename."'>"
   ."<img border='0' width='100px' src='".$row['filepath'].$row['filename']."' />"
   //."<img src='".$filename."' rel='lightbox['".$aid."']' border='0' width='100px' />"
   ."</a><br/></div>";
}
echo "</div>";

/******  build the pagination links ****/
// range of num links to show
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
   // show << link to go back to page 1
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
   // get previous page num
   $prevpage = $currentpage - 1;
   // show < link to go back to 1 page
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
} // end if 

// loop to show links to range of pages around current page
for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
   // if it's a valid page number...
   if (($x > 0) && ($x <= $totalpages)) {
      // if we're on current page...
      if ($x == $currentpage) {
         // 'highlight' it but don't make a link
         echo " [<b>$x</b>] ";
      // if not current page...
      } else {
         // make it a link
         echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
      } // end else
   } // end if 
} // end for
                 
// if not on last page, show forward and last page links        
if ($currentpage != $totalpages) {
   // get next page
   $nextpage = $currentpage + 1;
    // echo forward link for next page 
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
   // echo forward link for lastpage
   echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
} // end if
/****** end build pagination links ******/

echo "</div>";
echo "</div>";
echo "</div>";


// include the page footer
include('includes/template/footer.php');
mysql_close($con);
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.