使用AJAX的PHP MySQL的实现具有分页功能的搜索 [英] Implementing a search with paging using ajax php mysql

查看:106
本文介绍了使用AJAX的PHP MySQL的实现具有分页功能的搜索的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,伙计,我尝试使用AJAX,PHP和MySQL,jquery.Now我的应用程序工作正常,当我去到一个列表页面(实现在一个网站搜索功能网页与项目名单上的网站).But我有,其结果必须对清单page.Basic分页显示的是通过使用PHP和工程,从菜单中传来的链接,但失败的搜索索引页面上的搜索。(从索引页使用的搜索查询不工作即如果重定向)

搜索文本框:

 <表格名称=homePageSearchForm方法=邮报行动=cities.php自动完成=关闭>
                 <! - <输入类型=隐藏值=如kolte帕蒂尔生活的共和国,wagholi浦那ID =hiddenExDataNAME =hiddenExData>  - >
                    < D​​IV的风格=填充顶:5像素;行高:20像素;宽度:280px;类=FLT>
                    < D​​IV CLASS =FLT><强>局部性,市,生成器或项目名称和LT; / STRONG><跨度风格=颜色:#FF3300;> *< / SPAN>< BR>
                    < D​​IV CLASS =FLT><输入类型=文本的onblur =如果(THIS.VALUE =='')THIS.VALUE ='如kolte帕蒂尔生活的共和国,wagholi浦那;的onfocus =如果(THIS.VALUE =='如kolte帕蒂尔生活的共和国,wagholi浦那')THIS.VALUE ='';值=如kolte帕蒂尔生活的共和国,wagholi浦那NAME =SearchValueID =searchId称号=搜索类=headerinput ac_input自动完成=关闭>
 

列表页DIV其中的内容已经显示出来。

 < D​​IV CLASS =FLT width710ID =displayProp>
            < D​​IV的风格=的margin-top:10px的;类=FLT mapnewalert> < PHP //回声ucfirst($ _ SESSION ['$城市'])>< / DIV>
            < D​​IV的风格=浮动:正确的ID =toppagesel>
            < PHP
                    回声$ pages-> display_pages();
                    回声$ pages-> display_items_per_page();
                / *如果(使用isset($ localitySearch)及和放大器; $ localitySearch ='!'和;&安培;使用isset($城市搜索)及和放大器;!$城市搜索='')
                    {
                        $查询=SELECT * FROM内在特性加入关于properties.city_id = cities.city_id内连接本地城市的properties.locality_id = locality.locality_id其中(cities.city_name像%。$城市搜索。%和locality.locality_name像'%$ localitySearch。%)和1978紫胶之间(property_price_min'和'80紫胶)$ pages->的限制;
                    } * /

                //  其他
                // {
                    $查询=SELECT * FROM性质,地区,城市,properties.city_id ='。$ _ SESSION ['$ cityId'。和properties.locality_id = locality.locality_id和properties.city_id = cities.city_id $ pages- >的限制;
                //}

                //回声$查询;
                    $结果= mysql_query($查询)或死亡(mysql_error());

                    // $的getProperty = $ propertyDetails-> getPropertyDetailsByCityIdPaginate($ _ SESSION ['$ cityId'],$限制);
            ?>
            < // PHP的回声$ pages-> display_pages(); ?>< // PHP的回声$ pages-> display_items_per_page();?>
            < / DIV>
        < / DIV>
 

现在就点击搜索按钮我调用JavaScript函数如下:

 <输入类型=提交的onClick =** handleHomePageSearch(0,'E')**;返回false;值=搜索类=hpnewsubmitbtn>
 

JS的功能:

 函数handleHomePageSearch(buttonEle,E){
             VAR标准=的document.getElementById(searchCriteria)值。
            VAR searchVal =的document.getElementById(searchId)值。
            xmlHttpSearchct = GetXmlHttpObject();
            VAR cur_page =的document.getElementById(current_page)的innerHTML。

            变种的url =fetchCity.php&安培; searchVal =+ searchVal +与& buttonEle =+ buttonEle +与& cur_page =+ cur_page;
            警报(URL);
            xmlHttpSearchct.open(GET,网址,虚假);

            xmlHttpSearchct.send(空);

                           VAR Searchres = xmlHttpSearchct.responseText;
                       ** //获得响应**
                        xmlhttp.onreadystatechange =功能()
          {
              如果(xmlhttp.readyState == 4和&安培; xmlhttp.status == 200)
                {
                                    的document.getElementById('displayProp)的innerHTML = Searchres。
                }
          }
 

这使得响应返回到HTML的形式,但我不能够到列表(properties.php)page.Also如果我去用搜索值的分页不起作用上显示。

fetchCity.php contans查询的搜索和HTML返回数据。

  $ searchValue = $ _GET ['searchVal'];
$ buttonEle = $ _GET ['buttonEle'];
$ current_page = $ _ GET ['cur_page'];

    $ locCity =爆炸(,$ searchValue);
    $ localitySearch = $ locCity [0];
    $城市搜索= $ locCity [1];

        $查询=SELECT * FROM内在特性加入关于properties.city_id = cities.city_id内连接本地城市的properties.locality_id = locality.locality_id其中(cities.city_name像%。$城市搜索。%和locality.locality_name像'%$ localitySearch。%)和1978紫胶之间(property_price_min'和'80紫胶)$ pages->的限制;
    //回声$查询;
    出口;
    $结果= mysql_query($查询)或死亡(mysql_error());


?>


< D​​IV CLASS =width710ID =displayProp>

     < PHP


/ *的print_r($的getProperty);
的foreach($结果为$属性)* /
而($行= mysql_fetch_assoc($结果))
{
      ?>
            < D​​IV CLASS =projectlisttiger>
            < D​​IV CLASS =proptigerhead> PropTiger建议< / DIV>
                < D​​IV CLASS =spacer5>&安培; NBSP;< / DIV>
                < D​​IV CLASS =listnewimg FLT>
                    < A HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php>
                        < IMG SRC =管理/上传/< PHP的echo($行['property_cover_image'])>? WIDTH =186HEIGHT =125的边界=0>
                        < IMG SRC =管理/上传/ Cilantra1 / 1cilantra-large.jpgWIDTH =186HEIGHT =125的边界=0>
                    &所述; / a取代;
                     < D​​IV CLASS =newlistlaunch>< A HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php>< IMG宽度=65高度=65的边界=0 SRC =图像/项目/ kolte-帕蒂尔/ cilantra / new_launch_blue.png>< / A>
                     < / DIV>
                < / DIV>

                < D​​IV CLASS =listright>
                    < D​​IV的风格=宽度:498px;高度:42PX;类=FLT>
                        < D​​IV CLASS =列表标识FLT>
                            < D​​IV CLASS =buildborder>< A HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php>< IMG宽度=80高度=36的边界=0 ALIGN =absmiddleALT =Kolte帕蒂尔SRC =管理/上传/<?PHP的回声$行['builder_logo']>>< / A>
                            < / DIV>
                               < D​​IV CLASS =tablistname>< A HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php>< PHP的echo $行['PROPERTY_NAME']>< / A>< / DIV>
                        < / DIV>
                        <?PHP的,如果($行['property_price_min']!= 0){&GT?;
                        < D​​IV CLASS =listprice>
                            < IMG宽度=18高度=18ALIGN =absmiddleSRC =图像/城市/ rupee_icon.gif> <?PHP的echo $行['property_price_min']>紫胶 - <?PHP的echo $行['property_price_max']>紫胶
                        < / DIV>
                        < PHP}其他{&GT?;
                        < D​​IV CLASS =listprice>
                             < IMG宽度=18高度=18ALIGN =absmiddleSRC =图像/城市/ rupee_icon.gif>价格上的请求
                        < / DIV>
                        < PHP}&GT?;

                    < / DIV>

                        < D​​IV CLASS =spacer3>&安培; NBSP;< / DIV> SPACER

                    < D​​IV CLASS =列表框>
                        < A HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php><强>地址< / STRONG>:??< PHP的回声$行['locality_name']&GT中,< ?PHP的echo $行['CITY_NAME']>< BR> <强>类型< / STRONG>:2BHK和放大器;放大器; 3BHK
                        < BR><强>尺寸:LT; / STRONG> <?PHP的echo $行['property_size_min']>平方英尺 - <?PHP的echo $行['property_size_max']>平方英尺&所述; / a取代;
                    < / DIV>

                    < D​​IV的风格=保证金左:-3px;类=FLT>
                        < D​​IV的风格=宽度:110px;类=FLT><风格=文本装饰:无; HREF =P-kolte  - 帕蒂尔,香菜,wagholi-pune.php><输入类型=按钮值=查看详情级=detail_project>< / A>
                        < / DIV>
                      < D​​IV的风格=宽度:110px;类=FLT><输入类型=按钮的onClick =showEnqForm('2659','香菜');返回false;值=报价请求级=enquire_project>< / DIV>
                    < / DIV>
                           < D​​IV CLASS =间隔>&安培; NBSP;< / DIV> SPACER
                < / DIV>
                < D​​IV CLASS =spacer15>&安培; NBSP;< / DIV> SPACER
       < / DIV>

   < PHP}
   出口;

  //回声&其中,P级= \PAGINATE \>页面:$ pages-> NUM_PAGES< / P>的\ n $ pages-&GT current_page;
   ?>

        < D​​IV CLASS =spacer15>&安培; NBSP;< / DIV>
       < / DIV>
 

我想知道的是,我的做法吧??我怎么可以显示其他网页上的搜索结果与分页的工作。

作为参考,我将添加一个参考网站具有类似功能的链接。

这是: http://www.proptiger.com/ 任何形式的建议或帮助将是AP preciated。
分页类:

 类分页程序{
变量$ items_per_page的;
变量$ items_total;
变量$ current_page;
变量$ NUM_PAGES;
变量$ mid_range;
变量$低;
变量$限制;
变量$回报;
变量$ default_ipp;
变量$查询字符串;
变量$ ipp_array;

功能分页程序()
{
    $这个 - > current_page = 1;
    $这个 - > mid_range = 2;
    $这个 - > ipp_array =阵列(2,4,6,8,10,'全部');
    $这个 - >中items_per_page =(!空($ _ GET ['IPP']))? $ _GET ['IPP']函数:$ this-> default_ipp;
}

功能PAGINATE()
{
    如果(使用isset($这个 - >!default_ipp))$这个 - > default_ipp = '10';
    如果($ _ GET ['IPP'] =='全部')
    {
        $这个 - > NUM_PAGES = 1;
          // $这个 - >中items_per_page = $这个 - > default_ipp;
    }
    其他
    {
        如果(is_numeric($这个 - >!items_per_page的)或$这个 - > items_per_page的< = 0)$这个 - >中items_per_page = $这个 - > default_ipp;
        $这个 - > NUM_PAGES = CEIL($这个 - > items_total / $这个 - > items_per_page的);
    }
    $这个 - > current_page =(使用isset($ _ GET ['页']))? (INT)$ _GET ['页']:1; //必须是数字> 0
    $prev_page = $这个 - > current_page-1;
    $ next_page = $这个 - > current_page + 1;
    如果($ _ GET)
    {
        $ ARGS =爆炸(&放大器;,$ _ SERVER ['QUERY_STRING']);
        的foreach($的args为$ ARG)
        {
            $ KEYVAL =爆炸(=$ ARG);
            如果($ KEYVAL [0] =页和$ KEYVAL [0] =IPP!)$这个 - >查询字符串=&放大器; 。 $ ARG;
        }
    }

    如果($ _ POST)
    {
        的foreach($ _ POST作为$关键=> $ VAL)
        {
            如果($关键=页和$键=IPP!)$这个 - >查询字符串=&放大器; $键= $ VAL;
        }
    }
    如果($这 - > NUM_PAGES→4)
    {
        $这个 - >返回=($这个 - > current_page> 1和$这个 - > items_total> = 10)? &其中;一类= \PAGINATE \ href=\"$_SERVER[PHP_SELF]?page=$$p$pv_page&ipp=$this->items_per_page$this->querystring\">« previous&所述; / A>中:&其中;跨度类= \无效\的href = \#\>&安培; LAQUO; previous&所述; /跨度>中;

        $这个 - > start_range = $这个 - > current_page  - 地板($这个 - > mid_range / 2);
        $这个 - > end_range = $这个 - > current_page +地板($这个 - > mid_range / 2);

        如果($这 - > start_range&所述; = 0)
        {
            $这个 - > end_range + = ABS($这个 - > start_range)+1;
            $这个 - > start_range = 1;
        }
        如果($这个 - > end_range> $这个 - > NUM_PAGES)
        {
            $这个 - > start_range  -  = $这个 - > end_range- $这个 - > NUM_PAGES;
            $这个 - > end_range = $这个 - > NUM_PAGES;
        }
        $这个 - >范围=范围($这个 - > start_range,$这个 - > end_range);

        为($ i = 1; $ I< = $这个 - > NUM_PAGES; $ I ++)
        {
            如果($这个 - >范围[0]> 2和$ I == $这个 - >范围[0])$这个 - >返回=...;
            //在所有页面中循环。如果第一个,最后,还是在范围内,显示
            如果($ I == 1或$我== $这个 - > NUM_PAGES或者in_array($ I,$这个 - >范围))
            {
                $这个 - &gt;返回=($ I == $这个 - &GT;!current_page和$ _GET [页] ='所有')。? &LT;一个标题= \转到页$我的$这 - &GT; NUM_PAGES \级= \当前\的href = \#\&GT; $ I&LT; / A&gt;中:&LT;一类= \PAGINATE \TITLE = \转到页$ I $的这 - &GT; NUM_PAGES \ href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ;
            }
            如果($这 - &GT;范围[$这 - &GT; mid_range-1]; $这 - &GT; NUM_PAGES-1和$ I == $这 - &GT;范围[$这 - &GT; mid_range-1]) $这个 - &GT;返回=...;
        }
        $这个 - &GT;收益率=(($这个 - &GT; current_page&LT; $这个 - &GT; NUM_PAGES和$这个 - &GT; items_total&GT;!= 10)和($ _ GET ['页'] ='所有' )和$这个 - &GT; current_page大于0)? &其中;一类= \PAGINATE \ href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next &功放; RAQUO;&LT; / A&GT; \ N:&LT;跨度类= \无效\的href = \#\&GT;&安培; RAQUO;下一步&LT; / SPAN&GT; \ N的;
        $这个 - &GT;收益率=($ _GET [页] =='全部')? &LT;一类= \当前\风格= \保证金左:10px的\的href = \#\&GT;所有&LT; / A&GT; \ N:&LT;一类= \分页\ 样式= \保证金左:10px的\的href = \$ _ SERVER [PHP_SELF]页= 1&安培; IPP =所有$这个 - &GT;查询字符串\&GT;所有&LT; / A&GT; \ N的;
    }
    其他
    {
        为($ i = 1; $ I&LT; = $这个 - &GT; NUM_PAGES; $ I ++)
        {
            $这个 - &GT;收益率=($ I == $这个 - &GT; current_page)? 其中&;类别= \当前\的href = \#\&GT; $ I&所述; / A&gt;中:&其中;一类= \PAGINATE \ href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ;
        }
        $这个 - &gt;返回=&LT;一类= \分页\的href = \$ _ SERVER [PHP_SELF]页= 1&安培; IPP =所有$这个 - &GT;查询字符串\&GT;所有&LT; / A&GT ; \ N的;
    }
    $这个 - &GT;低=($这个 - &GT; current_page&LT; = 0)? 0:($这 - &GT; current_page-1)* $这 - &GT; items_per_page的;
    如果($这个 - &GT; current_page&LT; = 0)$这个 - &GT;中items_per_page = 0;
    $这个 - &GT;限额=($ _ GET ['IPP'] =='全部')? :限制$这 - &GT;低,$这个 - &GT; items_per_page的;
}
功能display_items_per_page()
{
    $项目='';
    如果(使用isset($ _ GET [IPP])!)$这个 - &GT;中items_per_page = $这个 - &GT; default_ipp;
    的foreach($这个 - &GT; ipp_array为$ ipp_opt)$项目=($ ipp_opt == $这个 - &GT; items_per_page的)? &LT;选项选择的值= \$ ipp_opt \&GT; $ ipp_opt&LT; /选项&GT; \ N:&LT;期权价值= \$ ipp_opt \&GT; $ ipp_opt&LT; /选项&GT; \ N的;
    返回&LT;跨度类= \PAGINATE \&GT;每页显示:其中,/ SPAN&GT;&LT;选择类= \PAGINATE \ onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return假\&GT; $项目&lt; /选择&GT; \ N的;
}
功能display_jump_menu()
{
    为($ i = 1; $ I&LT; = $这个 - &GT; NUM_PAGES; $ I ++)
    {
        $选项=($ I == $这个 - &GT; current_page)? &LT;期权价值= \$ I \选择&GT; $ I&LT; /选项&GT; \ N:&LT;期权价值= \$ I \&GT; $ I&LT; /选项&GT; \ N的;
    }
    返回&LT;跨度类= \PAGINATE \&gt;页面:LT; / SPAN&GT;&LT;选择类= \PAGINATE \ onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return假\&GT; $选项&LT; /选择&GT; \ N的;
}
功能display_pages()
{
    返回$这个 - &gt;返回;
}
 

}

感谢

解决方案

  $(文件)。就绪(函数(){
    $('。分页)。住(点击,功能(五){
        即preventDefault();
        VAR btnPage = $(本);
        $阿贾克斯({
            网址:btnPage.attr(HREF),
            成功:函数(RESP){
                //取代目前的结果与新的成效。
                $('#project_section)HTML(RESP);
            },
            错误:函数(){
                window.location.href = btnPage.attr('的href');
            }
        });
    });
});
 

下面$(分页)是类的&LT的;李&GT; 在我的分页程序类。我在这里得到了答案 谢谢

Hey folks I am trying to implement a search functionality in a website using ajax,php,mysql,jquery.Now my application works fine when I go to a list page(Page with list of items on the site).But I have a search on the index page whose results have to be displayed on the list page.Basic pagination is done using php and works for the links coming from menu,but fails for search.(i.e if redirected from the index page using a search query it does not work)

The search text box:

        <form name="homePageSearchForm" method="post" action="cities.php" autocomplete="off">
                 <!--   <input type="hidden" value="e.g kolte patil life republic, wagholi pune" id="hiddenExData" name="hiddenExData">-->
                    <div style="padding-top:5px; line-height:20px; width:280px;" class="flt">
                    <div class="flt"><strong>Locality, City, Builder or Project name</strong><span style="color:#FF3300;">*</span><br>
                    <div class="flt"><input type="text" onBlur="if(this.value=='') this.value='e.g kolte patil life republic, wagholi pune';" onFocus="if(this.value=='e.g kolte patil life republic, wagholi pune') this.value='';" value="e.g kolte patil life republic, wagholi pune" name="SearchValue" id="searchId" title="Search" class="headerinput ac_input" autocomplete="off">

List page div where content has to be displayed.

            <div class="flt width710" id="displayProp">
            <div style="margin-top:10px;" class="flt mapnewalert"> <?php //echo ucfirst($_SESSION['$city']) ?></div>
            <div style="float:right" id="toppagesel">
            <?php 
                    echo $pages->display_pages();
                    echo $pages->display_items_per_page();
                /*  if(isset($localitySearch) && $localitySearch!='' && isset($citySearch) && $citySearch!='')
                    {
                        $query = "SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id where (cities.city_name like '%".$citySearch."%' and locality.locality_name like '%".$localitySearch."%') and (property_price_min between '78 Lacs' and '80 Lacs') $pages->limit";
                    }*/

                //  else
                //  {
                    $query = "SELECT * from properties,locality,cities where properties.city_id='".$_SESSION['$cityId']."' and properties.locality_id=locality.locality_id and properties.city_id=cities.city_id $pages->limit";
                //  }

                //  echo $query;
                    $result = mysql_query($query) or die(mysql_error());

                    //$getProperty =    $propertyDetails->getPropertyDetailsByCityIdPaginate($_SESSION['$cityId'],$limit);
            ?>
            <?php //echo $pages->display_pages(); ?><?php //echo $pages->display_items_per_page();?>
            </div>
        </div>

Now on clicking the search button I call a javascript function as follows

                   <input type="submit" onClick="**handleHomePageSearch(0,'e')**;return false;" value="SEARCH" class="hpnewsubmitbtn">

The js function:

             function handleHomePageSearch(buttonEle,e) {
             var criteria  = document.getElementById("searchCriteria").value;
            var searchVal = document.getElementById("searchId").value;
            xmlHttpSearchct=GetXmlHttpObject();
            var cur_page = document.getElementById("current_page").innerHTML;

            var url="fetchCity.php?&searchVal="+searchVal+"&buttonEle="+buttonEle+"&cur_page="+cur_page;
            alert(url);
            xmlHttpSearchct.open("GET",url,false);

            xmlHttpSearchct.send(null);

                           var Searchres=xmlHttpSearchct.responseText;
                       **//To get the response**
                        xmlhttp.onreadystatechange=function()
          {
              if (xmlhttp.readyState==4 && xmlhttp.status==200)
                {
                                    document.getElementById('displayProp').innerHTML=Searchres;
                }
          }

This gives the response back in the form of HTML but i am not able to display it on the list(properties.php) page.Also the pagination does not work if I go using the search values.

The fetchCity.php contans the query for the search and the HTML to return with data.

                   $searchValue= $_GET['searchVal'];
$buttonEle  = $_GET['buttonEle'];
$current_page=$_GET['cur_page'];

    $locCity = explode(" ",$searchValue);
    $localitySearch =   $locCity[0];
    $citySearch     =    $locCity[1];

        $query = "SELECT * from properties inner join cities on properties.city_id=cities.city_id inner join locality on properties.locality_id=locality.locality_id where (cities.city_name like '%".$citySearch."%' and locality.locality_name like '%".$localitySearch."%') and (property_price_min between '78 Lacs' and '80 Lacs') $pages->limit";
    //echo $query;
    exit;
    $result = mysql_query($query) or die(mysql_error());


?>


<div class="width710" id="displayProp">

     <?php 


/*print_r($getProperty);
foreach($result as $property)*/
while($row=mysql_fetch_assoc($result))
{
      ?>
            <div class="projectlisttiger">      
            <div class="proptigerhead">PropTiger Recommends</div>   
                <div class="spacer5">&nbsp;</div>
                <div class="listnewimg flt">
                    <a href="p-kolte-patil-cilantro-wagholi-pune.php">
                        <img src="admin/uploads/<?php echo ($row['property_cover_image']) ?>" width="186" height="125" border="0">
                        <img src="admin/uploads/Cilantra1/1cilantra-large.jpg" width="186" height="125" border="0">
                    </a>
                     <div class="newlistlaunch"><a href="p-kolte-patil-cilantro-wagholi-pune.php"><img width="65" height="65" border="0" src="images/projects/kolte-patil/cilantra/new_launch_blue.png"></a>
                     </div>                             
                </div>

                <div class="listright">
                    <div style="width:498px; height:42px;" class="flt">
                        <div class="list-logo flt">
                            <div class="buildborder"><a href="p-kolte-patil-cilantro-wagholi-pune.php"><img width="80" height="36" border="0" align="absmiddle" alt="Kolte Patil" src="admin/uploads/<?php echo $row['builder_logo']?>"></a>
                            </div>
                               <div class="tablistname"><a href="p-kolte-patil-cilantro-wagholi-pune.php"><?php echo $row['property_name'] ?></a></div>
                        </div>   
                        <?php if ($row['property_price_min']!=0) { ?>      
                        <div class="listprice">
                            <img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif"> <?php echo $row['property_price_min'] ?> Lacs - <?php echo $row['property_price_max'] ?> Lacs       
                        </div>
                        <?php } else { ?>
                        <div class="listprice">
                             <img width="18" height="18" align="absmiddle" src="images/city/rupee_icon.gif">Price on Request
                        </div>
                        <?php } ?>

                    </div>

                        <div class="spacer3">&nbsp;</div>        SPACER

                    <div class="listbox">
                        <a href="p-kolte-patil-cilantro-wagholi-pune.php"><strong>Address</strong>:<?php echo $row['locality_name'] ?>, <?php echo $row['city_name'] ?><br> <strong>Types</strong>: 2BHK &amp; 3BHK
                        <br><strong>Sizes:</strong> <?php echo $row['property_size_min'] ?> sqft - <?php echo $row['property_size_max'] ?> sqft </a>
                    </div>

                    <div style="margin-left:-3px;" class="flt">
                        <div style="width:110px;" class="flt"><a style="text-decoration:none;" href="p-kolte-patil-cilantro-wagholi-pune.php"><input type="button" value="View Details" class="detail_project"></a>
                        </div>     
                      <div style="width:110px;" class="flt"><input type="button" onClick="showEnqForm('2659','Cilantro'); return false;" value="Enquire Now" class="enquire_project"></div>
                    </div>
                           <div class="spacer">&nbsp;</div>        SPACER                                
                </div>
                <div class="spacer15">&nbsp;</div>                  SPACER
       </div>              

   <?php } 
   exit;

  // echo "<p class=\"paginate\">Page: $pages->current_page of $pages->num_pages</p>\n";
   ?>                         

        <div class="spacer15">&nbsp;</div>
       </div>

I would like to know is my approach right??How can I display the search results on the other page with pagination working.

For reference I will add the link of a reference site with similar functionality.

Here it is: http://www.proptiger.com/ Any kind of suggestions or help would be appreciated.
pagination class:

         class Paginator{
var $items_per_page;
var $items_total;
var $current_page;
var $num_pages;
var $mid_range;
var $low;
var $limit;
var $return;
var $default_ipp;
var $querystring;
var $ipp_array;

function Paginator()
{
    $this->current_page = 1;
    $this->mid_range = 2;
    $this->ipp_array = array(2,4,6,8,10,'All');
    $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
}

function paginate()
{
    if(!isset($this->default_ipp)) $this->default_ipp='10';
    if($_GET['ipp'] == 'All')
    {
        $this->num_pages = 1;
          //$this->items_per_page = $this->default_ipp;
    }
    else
    {
        if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
        $this->num_pages = ceil($this->items_total/$this->items_per_page);
    }
    $this->current_page = (isset($_GET['page'])) ? (int) $_GET['page'] : 1 ; // must be numeric > 0
    $prev_page = $this->current_page-1;
    $next_page = $this->current_page+1;
    if($_GET)
    {
        $args = explode("&",$_SERVER['QUERY_STRING']);
        foreach($args as $arg)
        {
            $keyval = explode("=",$arg);
            if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
        }
    }

    if($_POST)
    {
        foreach($_POST as $key=>$val)
        {
            if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
        }
    }
    if($this->num_pages > 4)
    {
        $this->return = ($this->current_page > 1 And $this->items_total >= 10) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">&laquo; Previous</a> ":"<span class=\"inactive\" href=\"#\">&laquo; Previous</span> ";

        $this->start_range = $this->current_page - floor($this->mid_range/2);
        $this->end_range = $this->current_page + floor($this->mid_range/2);

        if($this->start_range <= 0)
        {
            $this->end_range += abs($this->start_range)+1;
            $this->start_range = 1;
        }
        if($this->end_range > $this->num_pages)
        {
            $this->start_range -= $this->end_range-$this->num_pages;
            $this->end_range = $this->num_pages;
        }
        $this->range = range($this->start_range,$this->end_range);

        for($i=1;$i<=$this->num_pages;$i++)
        {
            if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
            // loop through all pages. if first, last, or in range, display
            if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
            {
                $this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of $this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
            }
            if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) $this->return .= " ... ";
        }
        $this->return .= (($this->current_page < $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All') And $this->current_page > 0) ? "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next &raquo;</a>\n":"<span class=\"inactive\" href=\"#\">&raquo; Next</span>\n";
        $this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\">All</a> \n":"<a class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
    }
    else
    {
        for($i=1;$i<=$this->num_pages;$i++)
        {
            $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
        }
        $this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\">All</a> \n";
    }
    $this->low = ($this->current_page <= 0) ? 0:($this->current_page-1) * $this->items_per_page;
    if($this->current_page <= 0) $this->items_per_page = 0;
    $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
}
function display_items_per_page()
{
    $items = '';
    if(!isset($_GET[ipp])) $this->items_per_page = $this->default_ipp;
    foreach($this->ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
    return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
}
function display_jump_menu()
{
    for($i=1;$i<=$this->num_pages;$i++)
    {
        $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
    }
    return "<span class=\"paginate\">Page:</span><select class=\"paginate\" onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return false\">$option</select>\n";
}
function display_pages()
{
    return $this->return;
}

}

Thanks

解决方案

$(document).ready(function () {
    $('.paginate').live('click', function (e) {
        e.preventDefault();
        var btnPage = $(this);
        $.ajax({
            url: btnPage.attr('href'),
            success: function (resp) {
                // replace current results with new results.
                $('#project_section').html(resp);
            },
            error: function () {
                window.location.href = btnPage.attr('href');
            }
        });
    });
});

Here $(".paginate") is the class of the <li> in my paginator class. I got the answer here Thanks

这篇关于使用AJAX的PHP MySQL的实现具有分页功能的搜索的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆