splitting a search into pages

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sandeep.n
Forum Newbie
Posts: 5
Joined: Wed Jan 16, 2008 11:03 pm

splitting a search into pages

Post 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>";


}
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: splitting a search into pages

Post 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.
sandeep.n
Forum Newbie
Posts: 5
Joined: Wed Jan 16, 2008 11:03 pm

Re: splitting a search into pages

Post 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...
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: splitting a search into pages

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
sandeep.n
Forum Newbie
Posts: 5
Joined: Wed Jan 16, 2008 11:03 pm

Re: splitting a search into pages

Post by sandeep.n »

thanks scott its workin fine
User avatar
jimthunderbird
Forum Contributor
Posts: 147
Joined: Tue Jul 04, 2006 3:59 am
Location: San Francisco, CA

Re: splitting a search into pages

Post 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
sandeep.n
Forum Newbie
Posts: 5
Joined: Wed Jan 16, 2008 11:03 pm

Re: splitting a search into pages

Post by sandeep.n »

ok i will look over it...
Post Reply