matthew9090 Posted March 24, 2011 Share Posted March 24, 2011 I've looked at loads of other scripts that highlight the page but none of them work on mine . Here's part of my code: $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; Link to comment https://forums.phpfreaks.com/topic/231611-php-pagination-hightlight-current-page/ Share on other sites More sharing options...
Psycho Posted March 24, 2011 Share Posted March 24, 2011 Well, you need a variable for the current page. Assuming the value is stored in the variable $current_page you would do something like below. Note I change $i to $page - always give your variables descriptive names. $page =1; for ($x=0;$x<$foundnum;$x=$x+$e) { $style = ($page = $current_page) ? 'font-weight:bold;' : ''; echo " <a href='search.php?search=$search&s=$x' style='{$style}'>$page</a> "; $page++; Also, what is the purpose of $x and $e in your code? I would just use a for() loop where the $page variable is incremented as needed. Link to comment https://forums.phpfreaks.com/topic/231611-php-pagination-hightlight-current-page/#findComment-1191821 Share on other sites More sharing options...
Faks Posted March 24, 2011 Share Posted March 24, 2011 http://www.phpfreaks.com/tutorial/basic-pagination full tutorial how to make it use it wise Link to comment https://forums.phpfreaks.com/topic/231611-php-pagination-hightlight-current-page/#findComment-1191822 Share on other sites More sharing options...
matthew9090 Posted March 24, 2011 Author Share Posted March 24, 2011 here is the full code: <?php //get data $button = $_GET['submit']; $search = $_GET['search']; $s = $_GET['s']; if (!$s) $s = 0; $e = 10; $next = $s + $e; $prev = $s - $e; if (strlen($search)<=2) echo "Must be greater then 3 chars"; else { echo "<br /><table><tr><td><a href = index.php></a></td><td><form action='search.php' method='GET'><a href ='index.php'><img src='logo.png' align='top' height='28' width='60'></img></a><input type='text' value='' size='50' name='search' value='$search'> <input type='submit' name='submit' value='Search'></form></td></tr></table>"; //connect to database mysql_connect("localhost","root",""); mysql_select_db("test"); //explode out search term $search_exploded = explode(" ",$search); foreach($search_exploded as $search_each) { //construct query $x++; if ($x==1) $construct .= "keywords LIKE '%$search_each%'"; else $construct .= " OR keywords LIKE '%$search_each%'"; } //echo outconstruct $constructx = "SELECT * FROM search WHERE $construct"; $construct = "SELECT * FROM search WHERE $construct LIMIT $s,$e"; $run = mysql_query($constructx); $foundnum = mysql_num_rows($run); $run_two = mysql_query("$construct"); if ($foundnum==0) echo "No results found for <b>$search</b>"; else { echo "<table bgcolor='#0000FF' width='100%' height='1px'><br /></table><table bgcolor='#f0f7f9' width='100%' height='10px'><tr><td><div align='right'><b>$foundnum</b> result(s) found for <b>$search.</b></div></td></tr></table><p>"; while ($runrows = mysql_fetch_assoc($run_two)) { //get data $title = $runrows['title']; $desc = $runrows['description']; $url = $runrows['url']; echo "<table width='300px'> <h4><a href='http://$url'><b>$title</b></a><br /> $desc<br> <font color='00CC00'>$url</font></table></h4> "; } ?> <table width='100%'> <tr> <td> <div align="center"> <?php if (!$s<=0) echo "<a href='search.php?search=$search&s=$prev'>Prev</a>"; $i =1; for ($x=0;$x<$foundnum;$x=$x+$e) { echo " <a href='search.php?search=$search&s=$x'>$i</a> "; $i++; } if ($s<$foundnum-$e) echo "<a href='search.php?search=$search&s=$next'>Next</a>"; } } ?> </div> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/231611-php-pagination-hightlight-current-page/#findComment-1191831 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.