MDanz Posted August 20, 2009 Share Posted August 20, 2009 you can check my website for an example... http://www.u-stack.com/search.php?search=basketball&submit=search when you you go to next.. everything is fine.. then go back to previous, the results are different? :'( <?php mysql_connect("localhost", "Master", "password"); mysql_select_db("Ustack"); $button = $_GET['submit']; $search = $_GET['search']; if(!$button){ echo "<br>You didn't submit a keyword"; }else{ if(!isset($search) || strlen($search)<=2){ echo "<br><font color=white><br>search term too short</font>"; }else{ echo "<br><br><font color=white><br>you searched for <b>$search</b></font><hr size='1'>"; } //explode our search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each){ //construct query $x++; if($x==1){ $construct .= " `keywords` LIKE '%$search_each%'"; }else{ // these both need spaces. $construct .= " OR `keywords` LIKE '%$search_each%'"; } $construct = "SELECT * FROM `Stacks` WHERE $construct"; } // How many items to show per page $limit = 5; $page = $_GET['page']; if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } $construct = $construct.' LIMIT '.$start.' , '.$limit; $run = mysql_query($construct); $foundnum = mysql_num_rows(mysql_query('SELECT * FROM `Stacks`')); echo mysql_error(); if ($foundnum==0){ echo "<br><br><font color=white>No Stacks Found</font>"; }else{ echo "<font color=white>$foundnum <img src='http://www.u-stack.com/mini%20stack.jpg'> Found!</font><hr size='1'><p>"; echo '<table '.$margin.'>'; //here you do your loop like while ($runrows = mysql_fetch_assoc($run)){ //get data <== all thi is very not needed. $id = $runrows['id']; $name = $runrows['name']; $image = $runrows['image']; $hyperlink = $runrows['hyperlink']; $currency = $runrows['currency']; $info = $runrows['info']; $type = $runrows['type']; $rating = $runrows['rating']; echo '<td><tr>'; echo "<a href='$hyperlink'><img src='http://www.u-stack.com/Stack.jpg'></a>"; echo "</tr><font color=white><strong> $name - $info - $rating <a href='rate.php?id=$id'><img src='http://www.u-stack.com/rate.jpg'></a></center><br><br><hr size='1'></strong></font></td>"; } echo '</table>'; } // How many adjacent pages should be shown on each side? $adjacents = 3; // Your file name (the name of this file) $targetpage = "search.php"; if ($page == 0){ $page = 1; } $prev = $page - 1; $next = $page + 1; $lastpage = ceil($foundnum/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1){ $pagination .= "<div class=\"pagination\">"; // Previous if ($page > 1){ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$prev\">« previous</a>"; }else{ $pagination .= "<span class=\"disabled\">« previous</span>"; } // Pages if ($lastpage < (7 + ($adjacents * 2))){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$counter\">$counter</a>"; } } }elseif($lastpage > (5 + ($adjacents * 2))){ if($page < 1 + ($adjacents * 2)){ for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$counter\">$counter</a>"; } } } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$lastpage\">$lastpage</a>"; }elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=2\">2</a>"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$counter\">$counter</a>"; } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$lpm1\">$lpm1</a>"; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=$lastpage\">$lastpage</a>"; }else{ $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=1\">1</a>"; $pagination .= "<a href=\"$targetpage?$targetpage?search=".$_GET['search']."&submit=search&page=2\">2</a>"; $pagination .= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\">$counter</span>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&submit=search&page=$counter\">$counter</a>"; } } } // Next if ($page < $counter - 1){ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&submit=search&page=$next\">next »</a>"; }else{ $pagination .= "<span class=\"disabled\">next »</span>"; $pagination .= "</div>\n"; } echo $pagination; } ?> Link to comment https://forums.phpfreaks.com/topic/171083-previous-button-doesnt-work/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.