Jump to content

following a link from search script


AdRock

Recommended Posts

I don't know if this is a SQL problem and a PHP problem

 

I made my own search engine for my site and I hve got links that point to pages.  The problem is that the link i create has to right page i want to show and i can show the page by editing my code but i won't have any pagination links

 

Say i have a link called news.php?id=10 i can follow the link and i could show the page but i want to be able to show the extra links for other news.  This id may be the 7th record in the database so i would have 6 links before it

 

Is there a way i can find out the position that record is in the database or is there another way i can do it so that the pagination link of this page is in the correct place

 

At the moment with the code i've shown it shows the first record in the database and i have a theory if i can get the position of the record in the database i can say what pagenum it should be

 

<?php
	require_once('php/database/MySQL.php');
require_once('php/database/connection.php');
require_once('php/init.php');

    // Include the header html
    require_once("header.inc.php");
?>
<h1>Latest News</h1>
<div id="news">
<?php 

$dir = "about";
$path = "latest-news";
$webpage = basename($path); 

$db = & new MySQL($host,$dbUser,$dbPass,$dbName);

$count="Select COUNT(*) FROM news";
$sql="SELECT * FROM `news`";

// Perform a query getting back a MySQLResult object
$res = $db->query($count);
$result = $db->query($sql);

//get the number of rows in datatbase
$getresult = $result->size();

$numrows = $res->fetchrow();
  
if(isset($_GET['pagenum'])?$page = $_GET['pagenum']:$page = 1); 
$entries_per_page = 1;   

$total_pages = ceil($numrows[0]/$entries_per_page); 
$offset = (($page * $entries_per_page) - $entries_per_page); 
				   						
$sql="SELECT * FROM `news` LIMIT $offset,$entries_per_page";

// Perform a query getting back a MySQLResult object
$result = $db->query($sql);

$err = $result->size();

if($err == 0) {
echo ("No matches met your criteria."); 
} else {
// Iterate through the results
while ($row = $result->fetch()) {
	$content = htmlentities($row['content']);

	echo '<div id="images">
			<img src="images/honeylandsbuilding.jpg" alt="Honeylands building" title="Honeylands building" class="divimg" />
			<img src="images/front.jpg" alt="Honeylands front entrance" title="Honeylands front entrance" class="divimg" />
		</div><p>'.nl2br($row['content']).'</p>';
}
//or after the results
if($getresult > 1) pagination_one($total_pages,$page);;
}
echo "</div>";	

require_once("footer.inc.php");
?>

Link to comment
Share on other sites

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.