Jump to content

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);

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.