Consider area=Mumbai and category=lawn. and if there is only 7 records into the database then i want first four to get display in first page and remaining 3 into the same page on clicking the next button..
Here is my code:
Expand|Select|Wrap|Line Numbers
- <?php
- $link=mysql_connect("localhost","root","");
- mysql_select_db("celebration_db",$link);
- $q="select count(*) \"total\" from hallinfo";
- $ros=mysql_query($q,$link);
- $row=(mysql_fetch_array($ros));
- $total=$row['total'];
- $dis=4;
- $total_page=ceil($total/$dis);
- $page_cur=(isset($_GET['page']))?$_GET['page']:1;
- $k=($page_cur-1)*$dis;
- $category = $_GET['category'];
- $area = $_GET['area'];
- //$category = 'hall';
- //$area = 'nagpur';
- echo $category;
- echo $area;
- $q="select * from hallinfo where category = '$category' AND area = '$area' limit $k,$dis";
- //$q="select * from hallinfo limit $k,$dis";
- $ros=mysql_query($q,$link);
- while($row=mysql_fetch_array($ros))
- {
- $imageId = $row['id'];
- echo '<div id="pattern">';
- echo '<table>';
- echo '<tr>';
- echo '<td colspan="2" width="300px" height="200px">
- <img src="image-show.php?id='.$imageId.'">';
- echo '</td>';
- echo '<td width="150px" height="200px">'.$row['description'];
- echo '</td>';
- echo '</tr>';
- echo '<tr>';
- echo '<td>'.$row['rent'];
- echo '</td>';
- echo '<td>'.$row['capacity'];
- echo '</td>';
- echo '<td>'.$row['area'];
- echo '</td>';
- echo '</tr>';
- echo '</table>';
- echo '</div>';
- }
- //echo '</table>';
- //echo '<br/>';
- if($page_cur>1)
- {
- echo '<a href="pagination.php?page='.($page_cur-1).'" style="cursor:pointer;color:green;" ><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Previous "></a>';
- }
- else
- {
- echo '<input style="background-color:green;border:1px black solid;border-radius:5px;width:120px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value=" Previous ">';
- }
- for($i=1;$i<$total_page;$i++)
- {
- if($page_cur==$i)
- {
- echo ' <input style="background-color:green;border:2px black solid;border-radius:5px;width:30px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value="'.$i.'"> ';
- }
- else
- {
- echo '<a href="pagination.php?page='.$i.'"> <input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:30px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value="'.$i.'"> </a>';
- }
- }
- if($page_cur<$total_page)
- {
- echo '<a href="pagination.php?page='.($page_cur+1).'"><input style="cursor:pointer;background-color:green;border:1px black solid;border-radius:5px;width:90px;height:30px;color:white;font-size:15px;font-weight:bold;" type="button" value=" Next "></a>';
- }
- else
- {
- echo '<input style="background-color:green;border:1px black solid;border-radius:5px;width:90px;height:30px;color:black;font-size:15px;font-weight:bold;" type="button" value=" Next ">';
- }
- ?>