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>";
}
splitting a search into pages
Moderator: General Moderators
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: splitting a search into pages
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.
http://www.php-mysql-tutorial.com/php-mysql-paging.php is a good place to start.
Re: splitting a search into pages
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...
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
You don't post them. Your links to the next pages should be like script.php?name=whatever¶m=value&page=3
Use $_GET.
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.
Re: splitting a search into pages
thanks scott its workin fine
- jimthunderbird
- Forum Contributor
- Posts: 147
- Joined: Tue Jul 04, 2006 3:59 am
- Location: San Francisco, CA
Re: splitting a search into pages
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
http://www.scscertified.com/ecoproducts ... /index.php
Re: splitting a search into pages
ok i will look over it...