i not know part of codes wrong.
this need,
i need search range of dates of records , display onto table in php page.
start: (text field)
end : (text field) (submit button)
when key in start text field area, i'm able retrieve information requested , pagination ok.
once keyed in 2 text fields. restest.php page manage display first 50 values on table page number.
for example: date 1 = 07/06/2015 date 2 = 07/27/2015
i supposed have 142 rows limit 50. page display table of 50 rows 3 numbers of page.
1 2 3 but once clicked page 2 or next or other pages page display results of date 1 have 80 records , 2 pages.
1 2 this codes index.php
<html> <head> <title>title of search engine</title> </head> <body> <form action='restest.php' method='get'> <center> <h1>my search engine</h1> <input type='text' size='90' name='search'></br></br> <input type='text' size='90' name='end'></br></br> <input type='submit' name='submit' value='search source code' ></br></br></br> </center> </form> </body> </html> this codes restest.php
$button = $_get ['submit']; $s = $_get ['search']; $e = $_get ['end']; $search_exploded = explode (" ", $s, $e); $x = ""; $construct = ""; $constructs ="select * records date >='".$s."' , date <= '".$e."' "; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); echo $foundnum; $per_page = 50; $start = isset($_get['start']) ? $_get['start']: ''; $max_pages = ceil($foundnum / $per_page); if(!$start) $start=0; $getquery = mysql_query("select * records date >= '".$s."' , date <= '".$e."' "); echo "<table id=wtable>"; echo "<table id=htable style=width:800px; border=1px;> <tr style=background-color:black;color:yellow;font-size:18px;> <td style=width:200px>username</th> <td style=width:175px>date</th> <td style=width:225px>a</th> <td style=width:200px>b</th> </tr>"; echo "</table>"; echo "<div id ='test' style=width:820px;height:200px;overflow:auto;>"; echo "<table id=dtable width=800px border=1px>"; while($row = mysql_fetch_assoc($getquery)) { echo "<tr style=color:black;background-color:grey;font-size:13px;>"; echo "<td style=width:200px>" . $row['username'] . "</td>"; echo "<td style=width:175px >" . $row['date'] . "</td>"; echo "<td style=width:225px>" . $row['a'] . "</td>"; echo "<td style=width:200px>" . $row['b'] . "</td>"; echo "</tr>"; } echo "</table>"; echo "</table>"; echo "</div>"; //pagination starts echo "<center>"; $prev = $start - $per_page; $next = $start + $per_page; $adjacents = 3; $last = $max_pages - 1; if($max_pages > 1) { //previous button if (!($start<=0)) echo " <a href='restest.php?search=$s&submit=search&start=$prev'>prev</a> "; //pages if ($max_pages < 7 + ($adjacents * 2)) //not enough pages bother breaking { $i = 0; ($counter = 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='restest.php?search=$s&submit=search&start=$i'><b>$counter</b></a> "; } else { echo " <a href='restest.php?search=$s&submit=search&start=$i'>$counter</a> "; } $i = $i + $per_page; } } elseif($max_pages > 5 + ($adjacents * 2)) //enough pages hide { //close beginning; hide later pages if(($start/$per_page) < 1 + ($adjacents * 2)) { $i = 0; ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $start){ echo " <a href='restest.php?search=$s&submit=search&start=$i'><b>$counter</b></a> "; } else { echo " <a href='restest.php?search=$s&submit=search&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide front , elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2)) { echo " <a href='restest.php?search=$s&submit=search&start=0'>1</a> "; echo " <a href='restest.php?search=$s&submit=search=$per_page'>2</a> .... "; $i = $start; ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++) { if ($i == $start){ echo " <a href='restest.php?search=$s&submit=search&start=$i'><b>$counter</b></a> "; } else { echo " <a href='restest.php?search=$s&submit=search&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //close end; hide pages else { echo " <a href='restest.php?search=$s&submit=search&start=0'>1</a> "; echo " <a href='restest.php?search=$s&submit=search&start=$per_page'>2</a> .... "; $i = $start; ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='restest.php?search=$s&submit=search&start=$i'><b>$counter</b></a> "; } else { echo " <a href='restest.php?search=$s&submit=search&start=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($start >=$foundnum-$per_page)) echo " <a href='restest.php?search=$s&submit=search&start=$next'>next</a> "; } echo "</center>";
it seems in code relying on old, insecure , no longer available feature of php called register globals. register globals enabled, php automatically inject , post data (among others) variables, leading unpredictable , insecure results in code.
what should instead, use $_get or $_post directly, depending on type of data expect. in case, should use $_get['start'] start parameter sent script. or better, input validation on well. example:
$start = 0; if (!empty($_get['start']) && intval($_get['start']) > 0) { $start = intval($_get['start']); } for more information on processing , post-parameters, please check this page.
Comments
Post a Comment