rachae1 Posted January 19, 2009 Share Posted January 19, 2009 Hi, Can someone help me page records that I get from a keyword in an url. Currently my code looks like this: <?php $tag_id = $_GET['tag_id']; $query = mysql_query("SELECT * FROM news WHERE tag_id like '%$tag_id%' ORDER BY date_added DESC"); while($row = mysql_fetch_assoc($query)) { extract($row); include("include/keywordsummary.inc.php"); ?> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/141462-paging-from-a-keyword-in-the-url/ Share on other sites More sharing options...
.josh Posted January 19, 2009 Share Posted January 19, 2009 so what's the problem. Quote Link to comment https://forums.phpfreaks.com/topic/141462-paging-from-a-keyword-in-the-url/#findComment-740448 Share on other sites More sharing options...
rachae1 Posted January 19, 2009 Author Share Posted January 19, 2009 I would like someone to point me in the right direction so that I can page the data, I have the below paging code for something else but I cant get it to work with the like code. <?php if(!isset($_GET['page'])){$page = 1;} else {$page = $_GET['page'];} $max_results = 5; $from = (($page * $max_results) - $max_results); $total_results = mysql_result (mysql_query ("SELECT COUNT(*) AS num FROM link WHERE linkType='cars' "), 0); <?php $total_pages = ceil($total_results / $max_results); echo "<center><br />"; if($page > 1){$prev = ($page - 1); echo "<a title='Previous Page' href=\"".$_SERVER['PHP_SELF']."?page=$prev\"> ‹‹ Previous</a> ";} for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "Page $i ";} else {echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";} } if($page < $total_pages){ $next = ($page + 1); echo "<a title='Next Page' href=\"".$_SERVER['PHP_SELF']."?page=$next\"> Next ››</a>";} echo "<br/>"; echo "<br/>"; echo "</center><br />"; ?> <?php $query = mysql_query("SELECT * FROM link WHERE linkType='cars' ORDER BY h1 LIMIT $from, $max_results"); while($row = mysql_fetch_assoc($query)) { extract($row); Quote Link to comment https://forums.phpfreaks.com/topic/141462-paging-from-a-keyword-in-the-url/#findComment-740456 Share on other sites More sharing options...
.josh Posted January 19, 2009 Share Posted January 19, 2009 Read this tutorial to learn how pagination works. Then you should be able to easily integrate pagination into your script. Quote Link to comment https://forums.phpfreaks.com/topic/141462-paging-from-a-keyword-in-the-url/#findComment-740459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.