Sunday 15 July 2012

javascript - search data and keep data in Field -



javascript - search data and keep data in Field -

please review code solve problems.

when search info name or age, results in first 10 rows in page when move next page see result, goes results. how can go next page without info come in in name or age without remove or pages search in staying. when search info have problem null column in age if age null didn't appear need see info if it's null or not , come in type int age

class="snippet-code-html lang-html prettyprint-override"><table class="tab"> <thead> <tr> <th colspan="5" class="table-title"> <h3>search</h3> </th> </tr> <form method="post" action="<?php echo $_server['php_self']; ?>" id="searchform"> <tr class="trr"> <th class="thh"> total name </th> <th class="thh"> age </th> </tr> </thead> <tbody> <tr class="trr"> <td class="tdd"> <input type="text" autocomplete="off" style="width:150px;" name="name"> </td> <td class="tdd"> <input type="text" autocomplete="off" style="width:50px;" name="age"> </td> <td class="tdd"> <input type="submit" name="submit" value="search"> </td> </tbody> </table> </form> <br> </body> <?php if (!empty($_post['name'])){ $name=$_post['name']; } if (!empty($_post['age'])){ $age=$_post['age']; } $con=mysqli_connect("localhost","name","password","db"); $ch = 'set character set utf8'; mysqli_query($con,$ch); if (mysqli_connect_errno()) { echo "failed connect mysql: " . mysqli_connect_error(); } $tbl_name="table"; //your table name // how many adjacent pages should shown on each side? $adjacents = 3; /* first total number of rows in info table. if have clause in query, create sure mirror here. */ $resul = mysqli_query($con,"select id,full_name,age arrested full_name '%$name%' , age '%$age%'"); $num_rows = mysqli_num_rows($resul); $total_pages =$num_rows; /* setup vars query. */ $targetpage = "detainees.php"; //your file name (the name of file) $limit = 10; //how many items show per page if(isset($_get['page'])) {$page = $_get['page'];} else{$page =0;} if($page) $start = ($page - 1) * $limit; //first item display on page else $start = 0; //if no page var given, set start 0 /* setup page vars display. */ if ($page == 0) $page = 1; //if no page var given, default 1. $prev = $page - 1; //previous page page - 1 $next = $page + 1; //next page page + 1 $lastpage = ceil($total_pages/$limit); //lastpage = total pages / items per page, rounded up. $lpm1 = $lastpage - 1; //last page minus 1 /* apply our rules , draw pagination object. we're saving code variable in case want draw more once. */ $pagination = ""; if($lastpage > 1) { $pagination .= "<div class=\"pagination\">"; //previous button if ($page > 1) $pagination.= "<a href=\"$targetpage?page=$prev\">previous</a>"; else $pagination.= "<span class=\"disabled\">previous</span>"; //pages if ($lastpage < 7 + ($adjacents * 2)) //not plenty pages bother breaking { ($counter = 1; $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } elseif($lastpage > 5 + ($adjacents * 2)) //enough pages hide { //close beginning; hide later pages if($page < 1 + ($adjacents * 2)) { ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "<b class='dot'> . . . </b>"; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //in middle; hide front end , elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "<b class='dot'> . . . </b>"; ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } $pagination.= "<b class='dot'> . . . </b>"; $pagination.= "<a href=\"$targetpage?page=$lpm1\">$lpm1</a>"; $pagination.= "<a href=\"$targetpage?page=$lastpage\">$lastpage</a>"; } //close end; hide pages else { $pagination.= "<a href=\"$targetpage?page=1\">1</a>"; $pagination.= "<a href=\"$targetpage?page=2\">2</a>"; $pagination.= "<b class='dot'> . . . </b>"; ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) { if ($counter == $page) $pagination.= "<span class=\"current\">$counter</span>"; else $pagination.= "<a href=\"$targetpage?page=$counter\">$counter</a>"; } } } //next button if ($page < $counter - 1) $pagination.= "<a href=\"$targetpage?page=$next\">next</a>"; else $pagination.= "<span class=\"disabled\">next</span>"; $pagination.= "</div>\n"; } /* data. */ $resul = mysqli_query($con,"select id,full_name,age arrested full_name '%$name%' , age '%$age%' order id asc limit $start, $limit"); echo'<table class="table-fill">'; echo'<thead><tr class="data"> <th class="text-left">id</th> <th class="text-left">full name</th> <th class="text-left">age</th> </tr></thead> <tbody class="table-hover">'; while($x= mysqli_fetch_object($resul)) { echo '<tr class="data">'; echo '<td class="data">'; echo $x->id; echo "</td>"; echo '<td class="data">'; echo $x->full_name; echo "</td>"; echo '<td class="data">'; echo $x->status; echo "</td>"; echo "</tr>"; } print "</table>"; mysqli_close($con); ?> <?=$pagination ?>

use sessions ($_session), in example:

<?php session_start(); if (isset($_post['var']) && !empty($_post['var'])) { $var = $_post['var']; $_session['var'] = $var; } elseif (isset($_session['var'])) { $var = $_session['var']; } ?>

variables set in $_session kept until session ends (which when browser closed).

javascript php html html5

No comments:

Post a Comment