@session_start(); include 'connections.php'; $button = $_POST['submit']; $search = $_POST['searchvalue']; $name = $_POST['name']; if(strlen($search)<=1) { echo "Search term too short"; } else{ echo "You searched for $search <hr size='1'></br>"; $construct = "SELECT * FROM books WHERE category = '$name' AND (title LIKE '%$search%' or author LIKE '%$search%')"; $run = mysql_query($construct); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for $search.</br></br>1."; else { echo "$foundnum results found !<p>"; } $per_page = 2; $start = $_GET['start']; $max_pages = ceil($foundnum / $per_page); if($start) $start= ($start- 1) * $per_page; else $start=0; $query_with_limit = $construct . ' LIMIT ' . mysql_real_escape_string($start) .',' . mysql_real_escape_string($per_page); $getquery = mysql_query($query_with_limit); while($runrows = mysql_fetch_assoc($getquery)) { echo '<div class="news_box"> <a href="#">'; if($runrows ['cover_page_img']=="") { echo '<img class="news_image" src="'.INDEX_URL.'images/book_open.jpg" alt="image" width="90" height="90"/>'; } else{ echo '<img class="news_image" src="'.INDEX_URL.'images/BookCoverImgs/'.$row['cover_page_img'].'" alt="image" width="90" height="90"/>'; } echo ' </a> <h3><a href="#">'.$runrows ['title'].'</a></h3> <p> '.substr($runrows ['edition'],0,150).'.......</p> <div class="more float_r"><a href="#">Read more</a></div> <div class="cleaner"></div> </div>'; } $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='search.php?searchvalue=$search&submit&start=$prev'>Prev</a> "; //pages if ($max_pages < 7 + ($adjacents * 2)) //not enough pages to bother breaking it up { $i = 0; for ($counter = 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?searchvalue=$search&submit=$i'>$counter</a> "; } else { echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> "; } $i = $i + $per_page; } } elseif($max_pages > 5 + ($adjacents * 2)) //enough pages to hide some { //close to beginning; only hide later pages if(($start/$per_page) < 1 + ($adjacents * 2)) { $i = 0; for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $start){ echo " <a href='search.php?searchvalue=$search&submit=$i'>$counter</a> "; } else { echo " <a href='search.php?searchvalue=$search&submit=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide some front and some back elseif($max_pages - ($adjacents * 2) > ($start / $per_page) && ($start / $per_page) > ($adjacents * 2)) { echo " <a href='search.php?searchvalue=$search&submit=0'>1</a> "; echo " <a href='search.php?searchvalue=$search&submit&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start/$per_page)+1; $counter < ($start / $per_page) + $adjacents + 2; $counter++) { if ($i == $start){ echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> "; } else { echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> "; } $i = $i + $per_page; } } //close to end; only hide early pages else { echo " <a href='search.php?searchvalue=$search&submit=0'>1</a> "; echo " <a href='search.php?searchvalue=$search&submit&start=$per_page'>2</a> .... "; $i = $start; for ($counter = ($start / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $start){ echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> "; } else { echo " <a href='search.php?searchvalue=$search&submit&start=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($start >=$foundnum-$per_page)) echo " <a href='search.php?searchvalue=$search&submit&start=$next'>Next</a> "; } echo "</center>"; } ?>
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)