Jump to content

Paging from a keyword in the url


rachae1

Recommended Posts

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 }

?>

Link to comment
https://forums.phpfreaks.com/topic/141462-paging-from-a-keyword-in-the-url/
Share on other sites

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\"> &#8249;&#8249; 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 &#8250;&#8250;</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);

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.