Page 1 of 1

splitting a search into pages

Posted: Wed Jan 16, 2008 11:14 pm
by sandeep.n
Hi i have a search form which accepts three values , queries the database and displays the values of all the result in single page, i wanted to
display only 5 results per page .... Plz help me...
<<--- my code --->>

$value1=$_POST['1'];
$value2=$_POST['2'];
$value3=$_POST['3'];
$query1="select * from registration where mothertongue like '%$domain%' and religion like '%$religion%' and sex = '$sex' ";
$result=mysql_query($query1);
<?php while($row=mysql_fetch_assoc($result)){
extract ($row);

echo "<table border=1 class='black1' cellspacing='3' cellpadding='3' width='100%'> ";

echo "<tr><td class='bblack1' width='50%'>";
echo Name;
echo "</td>";
echo "<td>";
echo $firstname ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo Sex;
echo "</td>";
echo "<td>";
echo $sex ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo "Date of Birth" ;
echo "</td>";
echo "<td>";
echo $dob ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo "Mother Tongue";
echo "</td>";
echo "<td>";
echo $mothertongue ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo Religion;
echo "</td>";
echo "<td>";
echo $religion ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo Caste;
echo "</td>";
echo "<td>";
echo $caste ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo Country;
echo "</td>";
echo "<td>";
echo $country ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo State;
echo "</td>";
echo "<td>";
echo $state ;
echo"</td></tr>";

echo "<tr><td class='bblack1'>";
echo City;
echo "</td>";
echo "<td>";
echo $city ;
echo"</td></tr></table>";


}

Re: splitting a search into pages

Posted: Wed Jan 16, 2008 11:24 pm
by jimthunderbird
I guess you are going to deal with paging. This is a very common practice in a lot of applications.

http://www.php-mysql-tutorial.com/php-mysql-paging.php is a good place to start.

Re: splitting a search into pages

Posted: Wed Jan 16, 2008 11:44 pm
by sandeep.n
thank u jim for your concern ... but i am using a code like this


if (isset($_GET[“page”])) { $page = $_GET[“page”]; } else { $page=1; };
$start_from = ($page-1) * 5;
$query1="select * from registration where mothertongue like '%$value1%' and religion like '%$value2%' and sex = '$value3' LIMIT $start_from, 5";
$result=mysql_query($query1);
$query11="select count(username) from registration where mothertongue like '%$value1%' and religion like '%$value2%' and sex = '$value3' LIMIT $start_from, 2";
$result1=mysql_query($query11);
$res=mysql_fetch_row($result1);
$total_records = $res[0];
echo "$res[0]";
$total_pages = ceil($total_records / 2);
for ($i=1; $i<=$total_pages; $i++) {
echo "<a href='search.php?page='.$i.'>'.$i.'</a> ";
}
but the second time i select a page .... i am not able to post the values ..... i am not getting the idea of how to post without a form...
so please help me i am new here...

Re: splitting a search into pages

Posted: Wed Jan 16, 2008 11:53 pm
by s.dot
You don't post them. Your links to the next pages should be like script.php?name=whatever&param=value&page=3

Use $_GET.

Re: splitting a search into pages

Posted: Thu Jan 17, 2008 12:26 am
by sandeep.n
thanks scott its workin fine

Re: splitting a search into pages

Posted: Thu Jan 17, 2008 12:33 am
by jimthunderbird
Or if you know AJAX you can do paging effect using AJAX post, then you don't need an html form to do it. Like this one:

http://www.scscertified.com/ecoproducts ... /index.php

Re: splitting a search into pages

Posted: Thu Jan 17, 2008 12:55 am
by sandeep.n
ok i will look over it...