0
검색 키워드 텍스트 상자의 값을 기반으로 쿼리를 실행하는 코드가 필요합니다. 그러나 현재 코드는로드 할 때마다 기본 쿼리를 실행합니다 (도움말). 어떤 도움을 주시면 감사하겠습니다. Plz은 paging_class.php검색 쿼리는 검색 버튼을 클릭하지 않고 각로드시 자동으로 실행됩니다.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../css/style.css"> </link>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>RBlog - For the Consumers - By the Sellers</title>
<?
require_once("common/class.Database.php");
?>
</head>
<body>
<?php include("includes/header.php"); ?>
<?php include("dbclass/paging_class.php"); ?>
<div class="afterpicer_total">
<?php include("includes/menu.php"); ?>
<div class="wrapper">
<div class="cont">
<?php include("includes/left_menu.php"); ?>
<div class="reg_cont">
<form action="<? echo $_SERVER['PHP_SELF']; ?>" method="post">
<div class="reg_label">Looking for</div>
<div class="reg_tbox">
<select name="type" class="reg_combo_style">
<option>Living House</option>
<option>Office</option>
</select>
</div><br/>
<div class="reg_label">Rent/Month</div>
<div class="reg_tbox">
<select name="rent" class="reg_combo_style">
<option></option>
<option><2000</option>
<option>2000-4000</option>
<option>4000-6000</option>
<option>6000-10000</option>
<option>>10000</option>
</select>
</div><br/>
<div class="reg_label" >City</div>
<div class="reg_tbox">
<select name="city" class="reg_combo_style">
<option></option>
<option>Chennai</option>
<option>Salem</option>
<option>Madurai</option>
<option>Trichy</option>
</select>
</div><br/>
<div class="reg_label" >Area</div>
<div class="reg_tbox"><input type="text" size="32" name="area" class="reg_tbox_style" ></input></div><br/><br/>
<?php
//doPages(10, '/rentals_search.php', 'city=Madurai', 5);
$newpage=new paging();
$newpage->pager();
?>
<div class="reg_tbox"><input type="submit" name="subm" value="Search" class="reg_but_style"style="margin-left:155px;"></input></div>
<div class="reg_bl"></div>
</form>
</div>
</div>
<div class="adspace"> Advertisement Space</div>
</div>
</div>
</body>
</html>
rentals_search.template.php
도움이 당신이 당신의 Pager
클래스 $_GET
에서 값을 찾고있는 것 같습니다
<?php
ob_start();
require_once("common/class.Database.php");
require_once("common/varDeclare.php");
class paging extends Database
{
function pager()
{
$rowsPerPage = 3;
// by default we show first page
$pageNum = 1;
// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
$pageNum = $_GET['page'];
}
// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM rentals_ads" ." LIMIT $offset, $rowsPerPage";
//$query="SELECT * FROM ads WHERE rentals_type = 'Living House' AND rent > 50 AND rent < 300 AND city = 'London' AND area LIKE '%westminster%'"." LIMIT $offset, $rowsPerPage";
$result = mysql_query($query) or die('Error, query1 failed');
// print the random numbers
while($row = mysql_fetch_array($result))
{
echo $row['rentals_title'] . '';
echo $row['rentals_type'].' ';
echo $row['city'].'<br>';
}
// ... more code here
// ... the previous code
// how many rows we have in database
$query = "SELECT COUNT(rentals_title) AS numrows FROM rentals_ads";
$result = mysql_query($query) or die('Error, query2 failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);
// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';
for($page = 1; $page <= $maxPage; $page++)
{
if ($page == $pageNum)
{
$nav .= " $page "; // no need to create a link to current page
}
else
{
$nav .= " <a href=\"$self?page=$page\">$page</a> ";
}
}
// ... still more code coming
// ... the previous code
// creating previous and next link
// plus the link to go straight to
// the first and last page
if ($pageNum > 1)
{
$page = $pageNum - 1;
$prev = " <a href=\"$self?page=$page\">[Prev]</a> ";
$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
$prev = ' '; // we're on page one, don't print previous link
$first = ' '; // nor the first page link
}
if ($pageNum < $maxPage)
{
$page = $pageNum + 1;
$next = " <a href=\"$self?page=$page\">[Next]</a> ";
$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
$next = ' '; // we're on the last page, don't print next link
$last = ' '; // nor the last page link
}
// print the navigation link
echo $first . $prev . $nav . $next . $last;
// and close the database connection
// ... and we're done!
}
}
?>
// ---- End of addDB()------
감사합니다. 빠른 답변입니다. 내 요구 사항은 기본 쿼리가 먼저 실행되고 그 결과가 시작시에 표시되며,이를 중지하는 방법은 무엇입니까 ?? – Rajasekar
귀하의 의견을 언급 한 게시물을 수정했습니다. –
검색 버튼을 클릭 한 후 작업 결과가 나타납니다. 하지만 문제는 내가 두 번째 페이지 결과를 표시하지 않는 두 번째 페이지를 클릭 할 때입니다 ... – Rajasekar