title: php pagination and search
body: <p>i have a while loop with pagination i have i idea how to make a search just don't know how to insert it here's my code the pagination and output commands are working just don't know how to put the code for search and it's messing my head.</p>
  
  <pre><code>//Count the total number of row in your table*/
  $count_query   = mysql_query("SELECT COUNT(personid) AS numrows FROM persons");
  $row     = mysql_fetch_array($count_query);
  $numrows = $row['numrows'];
  $total_pages = ceil($numrows/$per_page);
  $reload = 'index.php';
  //main query to fetch the data 
  $query = mysql_query("SELECT * FROM persons ORDER by RAND() LIMIT $offset,$per_page");
  //loop through fetched data
  while($result = mysql_fetch_array($query)){
  $id = $result['PersonID'];
  echo "&lt;div class= content &gt; ";
  echo"&lt;img height=100 width=100 src='upload/". $result['Image'] ."'/&gt;";
  echo "&lt;font color='black'&gt;". $result['FirstName']. "&lt;/font&gt;&lt;/br&gt;";
  echo "&lt;/div&gt;";
  </code></pre>
  
  <p>so as i do trial and error i think the part i got error is the row here's my whole code</p>
  
  <pre><code>&gt; &lt;?php include_once('includes/dbConnect.php');
  &gt; 
  &gt; 
  &gt; ?&gt;
  &gt; 
  &gt; &lt;?php
  &gt; 
  &gt; // now you can display the results returned. But first we will display
  &gt; the search form on the top of the page
  &gt; 
  &gt; $searchText = $_POST["q"];
  &gt; 
  &gt; 
  &gt; 
  &gt; 
  &gt; 
  &gt; $action = (isset($_REQUEST['action'])&amp;&amp; $_REQUEST['action']
  &gt; !=NULL)?$_REQUEST['action']:'';
  &gt; 
  &gt; if($action == 'ajax'){
  &gt; 
  &gt;   include 'pagination.php'; //include pagination file
  &gt; 
  &gt; 
  &gt;   //pagination variables  $page = (isset($_REQUEST['page']) &amp;&amp;
  &gt; !empty($_REQUEST['page']))?$_REQUEST['page']:1;   $per_page = 5; //how
  &gt; much records you want to show     $adjacents  = 5; //gap between pages
  &gt; after number of adjacents     $offset = ($page - 1) * $per_page;
  &gt; 
  &gt;   //Count the total number of row in your table*/     $count_query   =
  &gt; mysql_query("SELECT COUNT(personid) AS numrows FROM persons");    $row  
  &gt; = mysql_fetch_array($count_query);    $numrows = $row['numrows'];     $total_pages = ceil($numrows/$per_page);    $reload = 'index.php';
  &gt; 
  &gt;                   //search
  &gt;         // basic SQL-injection protection
  &gt; 
  &gt;         $searchText = $_REQUEST["q"];     //main query to fetch the data
  &gt;         // query with simple search criteria $query = mysql_query("SELECT * FROM persons WHERE FirstName LIKE '%"
  &gt;            . $searchText . "%' ORDER by RAND() LIMIT $offset,$per_page");
  &gt; 
  &gt;   //loop through fetched data
  &gt; 
  &gt; 
  &gt;         while($result = mysql_fetch_array($query)){
  &gt;         $id = $result['PersonID'];
  &gt; 
  &gt; 
  &gt;                                       echo "&lt;div class= content &gt; ";
  &gt; 
  &gt;                                       echo"&lt;img height=100 width=100 src='upload/". $result['Image'] ."'/&gt;";
  &gt;                                       echo "&lt;font color='black'&gt;". $result['FirstName']. "&lt;/font&gt;&lt;/br&gt;";
  &gt; 
  &gt; 
  &gt; 
  &gt;                                       echo "&lt;/div&gt;";
  &gt; 
  &gt; 
  &gt; } echo paginate($reload, $page, $total_pages, $adjacents); } else{ ?&gt;
  &gt; 
  &gt; 
  &gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;title&gt;Simple Ajax
  &gt; Pagination With PHP And MySql&lt;/title&gt; &lt;script type="text/javascript"
  &gt; src="jquery-1.5.2.min.js"&gt;&lt;/script&gt; &lt;link media="screen"
  &gt; href="style.css" type="text/css" rel="stylesheet"&gt; &lt;script
  &gt; type="text/javascript"&gt;   $(document).ready(function(){       load(1);    });
  &gt; 
  &gt;   function load(page){        $("#loader").fadeIn('slow');        $.ajax({
  &gt;           url:'index.php?action=ajax&amp;page='+page,             success:function(data){
  &gt;               $(".outer_div").html(data).fadeIn('slow');
  &gt;               $("#loader").fadeOut('slow');           }       })
  &gt; 
  &gt;         }
  &gt; 
  &gt; &lt;/script&gt;
  &gt; 
  &gt; &lt;/head&gt; &lt;body&gt;
  &gt;  
  &gt; 
  &gt; 
  &gt; &lt;div id="loader"&gt;&lt;img src="loader.gif"&gt;&lt;/div&gt;
  &gt; 
  &gt; 
  &gt; 
  &gt; &lt;div class="outer_div"&gt;&lt;/div&gt;
  &gt; 
  &gt;     &lt;div class="content"&gt;&lt;form action='' method='POST'&gt; &lt;input type='text' name='q' /&gt; &lt;INPUT TYPE="button" onClick="history.go(0)"
  &gt; VALUE="Refresh"/&gt; &lt;/p&gt; &lt;/form&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; &lt;?php
  &gt; 
  &gt; }?&gt;
  </code></pre>
  
  <p>this is the output i want <br/>
  1: <a href="http://i.stack.imgur.com/l8MMA.png" rel="nofollow">http://i.stack.imgur.com/l8MMA.png</a> <br/>
  2: <a href="http://i.stack.imgur.com/p47UI.png" rel="nofollow">http://i.stack.imgur.com/p47UI.png</a> <br/></p>