简体   繁体   中英

php search form with pagination

im having the following issue with some php/javascript code. I have 3 pages: index.php | result.php and pagination.php . this is the code(really simple here):

index.php

<form action="result2.php" method="get" id="search">
<input type="text" id="query" name="query"/>
<input type="submit" id="mainsubmit" value="Search" />
</form>

result.php gets the data of the form, but my problem is the following: in result.php i use pagination, and i have a third page called pagination.php:

<?php
  //Print the contents

  while($row = mysql_fetch_array($rsd))
  {
    $id=$row['msg_id'];
    title=$row['title'];
?>
   //data goes here                 
<?php
  } //while
?>

ok, so I have that, the problem then (sorry for so many circles) is that the data from index.php is being sent to result.php that is where the data is being output, using javascript I use pagination.php

<script type="text/javascript">
  $(document).ready(function(){
    //Display Loading Image
    function Display_Load()
    {
      $("#loading").fadeIn(900,0);
      $("#loading").html("<img src='bigLoader.gif' />");
    }
    //Hide Loading Image
    function Hide_Load()
    {
      $("#loading").fadeOut('slow');
    };

    $("#pagination li:first").css({'color' : '#FF0084'}).css({'border' : 'none'});

    Display_Load();

    $("#results").load("pagination_data.php?page=1", Hide_Load());

    //Pagination Click
    $("#pagination li").click(function(){

      Display_Load();

      //CSS Styles
      $("#pagination li")
      .css({'border' : 'solid #dddddd 1px'})
      .css({'color' : '#0063DC'});

      $(this)
      .css({'color' : '#FF0084'})
      .css({'border' : 'none'});

      //Loading Data
      var pageNum = this.id;

      $("#results").load("pagination_data.php?page=" + pageNum, Hide_Load());
    });
  });
</script>

and in the top of result.php i have the following piece of code:

<?php
  include('config.php');
  $per_page = 9; 
  $sql = "select * from tabe where title='$data'";
  $rsd = mysql_query($sql);
  $count = mysql_num_rows($rsd);
  $pages = ceil($count/$per_page)
?>

So again what im trying to do is to make the form from index.php send me to result.php but also send the data to pagination.php sorry if this is very confused typed

Ok first your form target should be called result.php not result2.php . And also I'm not sure but aren't you trying to return the data from pagination_data.php

As I understand your question, you are trying to implement a search that splits 100 results into 10 pages. So the server needs to safe the result of the search query you entered in case the user loads the next page!

In PHP you can achieve such things using Sessions, a Session stores data in php for multiple requests. ( http://www.php.net/manual/en/function.session-start.php )

//result.php
<?php
    //Start your session
    session_start();

    //Safe whatever you want
    $_SESSION['my_key'] = array('my', 'funny', 'data');

    //Or print stuff previously safed in the session
    echo $_SESSION['last'];
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM