Jump to content

search by keyword and give possible results


joshgarrod

Recommended Posts

Hi, my script currently produces a list of all my results from my table, however than can be as many as 200 results and for practicality i have paginated them to 10 per page, but someone is not going to sit and scan through the whole list so I would like to create a keyword search facility. I am not sure as to how exactly I would go about this with my pagination script, what is my best bet?

 

Here is my current script:

 

<?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("host", "usr", "pass") or die(mysql_error()); 
		mysql_select_db("db") or die(mysql_error()); 

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

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

		echo "<p>We currently have $total_records spare parts listed</p>";

		echo "</div>";

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

		$orderby = "ASC";

		$query = ("SELECT * FROM spares ORDER BY ref $orderby LIMIT $start, $records_per_page");
		$result = mysql_query($query)
		or die ('Error in query: $query. ' . mysql_error());
		echo "<div id=\"next_prev\">";
		if ($start >= $records_per_page)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start-$records_per_page) . " class=\"next_prev\"><< Previous
		Page</a>     ";
		}
		if ($start+$records_per_page < $total_records && $start >= 0)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start+$records_per_page) . " class=\"next_prev\">Next Page >></a>";
		}
		echo "</div>";
		while($row = mysql_fetch_object($result)) 
		{ 
		//$price = number_format($row->price); //formatting the price field to use a thousand separator
			Print "<div id=\"spares_row\">";
					Print "<div class=\"image_info\"><a href='view_caravan_spare.php?ref=$row->ref'><img src=\"$row->image\" border=\"0\" height=\"75\" width=\"100\" alt=\"$row->title\" title=\"$row->title\" /></a><br />";
					Print "<a href='view_used_caravan.php?ref=$row->ref' title=\"More info on the $row->title\">More info>></a></div>";
					Print "<div id=\"specifications\">";
					Print "<div id=\"title_title\"><strong>Description: </strong></div><div id=\"answer\">$row->title</div>";
					Print "<div id=\"title_title\"><strong>Part no.: </strong></div><div id=\"answer\">$row->partno</div>";
					Print "<div id=\"title_title\"><strong>Price: </strong></div><div id=\"answer\">£$row->price</div>";						
				Print "</div>";
			Print "</div>";
		}
		}

		echo "<div id=\"next_prev\">";
		if ($start >= $records_per_page)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start-$records_per_page) . " class=\"next_prev\"><< Previous
		Page</a>     ";
		}
		if ($start+$records_per_page < $total_records && $start >= 0)
		{
		echo "<a href=" . $_SERVER['PHP_SELF'] .
		"?start=" . ($start+$records_per_page) . " class=\"next_prev\">Next Page >></a>";
		}
		echo "</div>";
		?>

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.