Jump to content

Pagination problems


joshgarrod

Recommended Posts

Hi all, I am having problems with pagination for my list of items. Bascially it works to the extent of showing only 10 results but when I click the Next Page link it goes to a url which is part of my local directory for the website... Any ideas? thanks in advance:

 

<?php
	error_reporting (E_ALL ^ E_NOTICE);

	$records_per_page = 10; //number of records to be displayed per page

	(!$_GET['start']) ? $start = 0 : $start = $_GET['start'];

		mysql_connect("serv", "usr", "pass") or die(mysql_error()); 
		mysql_select_db("quest") or die(mysql_error()); 

		$query = "SELECT COUNT(*) FROM table";
		$result = mysql_query($query)
		or die ('Error in query: $query. ' . mysql_error());

		$data = mysql_fetch_row($result);
		$total_records = $data[0];

		if (($total_records > 0) && ($start < $total_records))
		{

		//delete from here up to start of php is broke

		$cond = "";

		if(isset($_POST['weight']) && is_numeric($_POST['weight']))
		{
			$weight = intval($_POST['weight']);
			$cond = " WHERE weightla <= {$weight}";
		}

		$data = mysql_query("SELECT * FROM table LIMIT $start, $records_per_page".$cond);
		$result = mysql_query($query)
		or die ('Error in query: $query ' . mysql_error());
		while($info = mysql_fetch_array( $data )) 
		{ 

			Print "<div id=\"caravan_row\">";
				Print "<div id=\"logo\"><a href='view_used_caravan.php?ref=".$info['ref'] ."'><img src=\"images/".$info['make'] . ".gif\" border=\"0\" /></a></div>";
				Print "<div id=\"image\"><a href='view_used_caravan.php?ref=".$info['ref'] ."'><img src=\"".$info['image1'] . "\" border=\"0\" /></a></div>";
				Print "<div id=\"specifications\">";
					Print "<div id=\"make\"><h1></strong>".$info['make'] . " " . $info['model'] ."</h1></div>";
					Print "<div id=\"price\"><span class=\"price\">£".$info['price'] . "</span></div>";
					Print "<div id=\"more\"><a href='view_used_caravan.php?ref=".$info['ref'] ."'>More info>></a></div>";
					Print "<div id=\"year\"><strong>Year: </strong>".$info['year'] . " </div>";
					Print "<div id=\"weightun\"><strong>MIRO: </strong>".$info['weightun'] . "kg</div>";
					Print "<div id=\"berth\"><img src=\"images/".$info['berth'] . ".gif\" class=\"berth\" />" .$info['berth'] . " berth</div>";
					Print "<div id=\"weightla\"><strong>MTPLM: </strong>".$info['weightla'] . "kg</div>";
					Print "<div id=\"lengthex\"><strong>Shipping length: </strong>".$info['lengthex'] . "ft</div>";						
				Print "</div>";
			Print "</div>";
		}
		if ($start >= $records_per_page)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start-$records_per_page) . ">Previous
		Page</a>     ";
		}
		if ($start+$records_per_page < $total_records && $start >= 0)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start+$records_per_page) . ">Next Page</a>";
		}
		}
		?>

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.