Hi

Hi guys,

i want to do paging for my search result page.

i dont know how to implement paging in my search result…

my search coding:

<?php
	
//PAGGING...
	include("paging.php");

	
/*set varibles from form */
$city=$_REQUEST['city'];
$name=$_REQUEST['name'];


trim ($city);
trim ($name);


require_once("connect.php");
/*query the database*/
if (trim($city) !='' && trim($name) !='')
{
$query = "select * from tbl_search where `city`='$city' and `name` like '$name%'" ;
}
elseif  ($city !='')
{
$query = "select * from tbl_search where `city` like '$city'" ;
}
elseif ($name !='')
{
$query = "select * from tbl_search where `name` like '$name%'" ;
}

$result =mysql_query($query);

/*number of rows found*/
$num_rows = mysql_num_rows($result);

if ($num_rows == 0)
{
echo '<p><b><h1>No Records Found!! </h1></b></p>';
echo  '<p><a href="searchnew1.php"><img src="images/back button.jpg" width="106" height="50" border="0" /></a></p>';
exit();
}

echo '<p><b><h3>Lawyer Information: '.$num_rows.'</h3></b></p>';
/*loops through results*/
echo "<table class='helpHed' border='1'>
<tr>
<th>Name</th>
<th>Area</th>
<th>View Details</th>
<th>Website</th>
</tr>";



while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "<tr>";
 
 echo "<td>" . $row['name'] . "</td>";
   echo "<td>" . $row['area'] . "</td>";
    echo "<td class='class1'>".'<a href="' . $row['link'] . '">' . $row['view_details'] . '</a>'."</td>";
	echo "<td class='class2'>".'<a href="' . $row['w_link'] . '">' . $row['website_link'] . '</a>'."</td>";   
    echo "</tr>";
  }
echo "</table>";

 
/*free database*/
/*$result->free();*/


?>

also i have Paging.php for another one php file(advocate.php)
in tat file i use paging but i dont know how use in search result…

paging.php:

<?php
//Paging...
// Here $ Arg
//1.Table
//2.Fail Path...
//3.Starting Value...
//4.Limit Value...

	function paging($Table,$path,$Start,$limit)
	{
	$selectQuery="SELECT * FROM $Table";
	$Result=mysql_query($selectQuery);
	$lenght=mysql_num_rows($Result);
	?>
<link href="css/header.css" rel="stylesheet" type="text/css" />

	<link href="admin.css" rel="stylesheet" type="text/css" />
<table width="10%" border="0" align="right" cellpadding="5" cellspacing="0">
	  <tr>
		<?php 
	    $count=$Start;
		if($count!=0)
		{
			$count-=$limit;
		?>
		<td width="25%" align="left" valign="middle" class="mainmenu"><a href="<?php echo $path; ?>?Start=<?php echo $count;?>" class="mainmenu">Prev </a></td>
		<td width="25%" align="left" valign="middle" class="page">|</td>
		<?php 
		}
		else
		{ 
		?>
		<td width="50%" align="left" valign="middle" class="mainmenu">Prev</td>
		<?php 
		}
		?>
		
		<?php
		if($Start<$lenght-$limit)
		{
		$Start+=$limit;
		?>
		
		<td width="25%" align="right" valign="middle" class="mainmenu"><a href="<?php echo $path;?>?Start=<?php echo $Start; ?>" class="mainmenu">Next</a></td>
		<?php 
		}
		else
		{	
		?>
		<td width="50%" align="right" valign="middle" class="mainmenu">Next</td>
		<?php
		}
		?>
	  </tr>
</table>
	<span class="page">
	<?php
	
	}
	?>
    </span>

Pls help me guys…

If using MySQL results then the simplest way is to incorporate the LIMIT command in your query.

$sql = "SELECT {fields} FROM {table} LIMIT $start,$number";

$start is a variable defining the first record you want to show (0 for the very first item).
$number is a variable defining the quantity of records per page (e.g. 10).

So if values of 0 and 10 are used then records 0 to 9 will be displayed.

It is thus quite easy to pass these values between pages and define which records are to be displayed. :slight_smile: