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