Hello, i have a question about the results in the browser where you search. I want that this, Search+source+code&page=36 Search+source+code&page=72 Search+source+code&page=108 PHP: to change it like this, when you click next or 2 3 4 5 etc Search+source+code&page=2 Search+source+code&page=3 Search+source+code&page=4 PHP: is that possible ? here below the complete script <?php $button = $_GET ["submit"]; $search = $_GET ["search"]; if(strlen($search)<=1) echo "Search term too short"; else{ echo "You searched for <b>$search</b> <hr size='1'></br>"; mysql_connect("mysql_host_name","mysql_username","mysql_password"); mysql_select_db("database_name"); $search_exploded = explode (" ", $search); foreach($search_exploded as $search_each) { $x++; if($x==1) $construct .="title LIKE '%$search_each%'"; else $construct .="AND title LIKE '%$search_each%'"; } $constructs ="SELECT * FROM database_table_name WHERE $construct"; $run = mysql_query($constructs); $foundnum = mysql_num_rows($run); if ($foundnum==0) echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1. Try more general words. for example: If you want to search 'how to create a website' then use general keyword like 'create' 'website'</br>2. Try different words with similar meaning</br>3. Please check your spelling"; else { echo "$foundnum results found !<p>"; $per_page = 36; $page = $_GET["page"]; $max_pages = ceil($foundnum / $per_page); if(!$page) $page=0; $getquery = mysql_query("SELECT * FROM database_table_name WHERE $construct LIMIT $page, $per_page"); while($runrows = mysql_fetch_assoc($getquery)) { $title = $runrows ["title"]; $desc = $runrows ["description"]; $url = $runrows ["url"]; echo " <a href='$url'><b>$title</b></a><br> $desc<br> <a href='$url'>$url</a><p> "; } //Pagination pages echo "<center>"; $prev = $page - $per_page; $next = $page + $per_page; $adjacents = 3; $last = $max_pages - 1; if($max_pages > 1) { //previous button if (!($page<=0)) echo " <a href='search.php?search=$search&submit=Search+source+code&page=$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 == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$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(($page/$per_page) < 1 + ($adjacents * 2)) { $i = 0; for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } //in middle; hide some front and some back elseif($max_pages - ($adjacents * 2) > ($page / $per_page) && ($page / $per_page) > ($adjacents * 2)) { echo " <a href='search.php?search=$search&submit=Search+source+code&page=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... "; $i = $page; for ($counter = ($page/$per_page)+1; $counter < ($page / $per_page) + $adjacents + 2; $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } //close to end; only hide early pages else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=0'>1</a> "; echo " <a href='search.php?search=$search&submit=Search+source+code&page=$per_page'>2</a> .... "; $i = $page; for ($counter = ($page / $per_page) + 1; $counter <= $max_pages; $counter++) { if ($i == $page){ echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'><b>$counter</b></a> "; } else { echo " <a href='search.php?search=$search&submit=Search+source+code&page=$i'>$counter</a> "; } $i = $i + $per_page; } } } //next button if (!($page >=$foundnum-$per_page)) echo " <a href='search.php?search=$search&submit=Search+source+code&page=$next'>Next</a> "; } echo "</center>"; } } ?> PHP: Thank`s in advance.
shure, normaly we fetch first SELECT count(id) AS cnt FROM table WHERE.... then we know how much pages are available (result / number of items per page = number of available pages). After that you can create the query to read your items LIMIT $page * $numberOfItems, $numberOfItems where ofcource the first page should be 0 instead of 1.
@Eric Brugema, I tried step by step, to do as you say but i did not succeed, can you give me one other way and explain, thanks for your previous response. Are you living in the Netherlands? Eric Bruggema sound like it is from Netherlands.
Change occurrences of: &page=$x Code (markup): To: &page=($x/36)+1 Code (markup): and $page = $_GET["page"] * 36; Code (markup): That is not the optimal solution, optimal solution as stated above to correctly change the counts.
Thank you for the response but nothing happened, I've changed how it is explained. if i change $per_page = 1; Code (markup): than i have in the browser page=1, page=2 etc, but it shows me 1 video per page. A friend of mine has also tried to solve it but nothing. WELCOME TO THE WORLD OF PHP he told me. i am almost done and i fighting for days to solve this problem.