Jump to content

looking for a search script


mrdeleigh

Recommended Posts

but he's not wanting it ordered by date.. He wants to list blogs that are similar to the currently viewed one.. I think ;)

 

I guess you could have a field in the table called 'keywords' or similar and then the sidebar could just display the first 5 (or however many) bloggs that have some of thte same keywords.

thanks for the replys

 

but he's not wanting it ordered by date.. He wants to list blogs that are similar to the currently viewed one.. I think

 

I guess you could have a field in the table called 'keywords' or similar and then the sidebar could just display the first 5 (or however many) bloggs that have some of thte same keywords.

 

thats correct but instead of keywords can it search the blog text?

You could also just add keywords to your blog posts, and it could list posts with the same keywords by their date. That would be simplest.

already been suggested

 

but he's not wanting it ordered by date.. He wants to list blogs that are similar to the currently viewed one.. I think ;)

 

I guess you could have a field in the table called 'keywords' or similar and then the sidebar could just display the first 5 (or however many) bloggs that have some of thte same keywords.

You could use a FULLTEXT search, which ignores words less than 4 chars long. Have a play with this

 

::DATA::

CREATE TABLE `blog` (
  `id` int(10) unsigned NOT NULL auto_increment,
  `blogdate` date NOT NULL,
  `content` varchar(255) NOT NULL,
  PRIMARY KEY  (`id`),
  FULLTEXT KEY `FTIndex_2` (`content`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

INSERT INTO `blog` (`id`,`blogdate`,`content`) VALUES 
(1,'2007-01-01','Dolphins are aquatic mammals'),
(2,'2007-01-05','Gerbils are mammals'),
(3,'2007-01-10','bullrushes are aquatic plants'),
(4,'2007-01-15','My friend plants trees for a living'),
(5,'2007-01-20','My garden shed is built of bullrushes'),
(6,'2007-01-25','Dolphins are your friend');

 

::SCRIPT::

<?php
include '../test/db2.php';
if (isset($_GET['id']))
{
    $id = $_GET['id'];
    $sql = "SELECT id, blogdate, content
            FROM blog
            WHERE id = '$id' ";
    $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
    if (list ($id, $d, $c) = mysql_fetch_row($res))
    {
        echo '<b>', date('jS F', strtotime($d)), '</b><br>', $c, '<hr><b>Similar blog entries</b><hr>';
        
        $sql = "SELECT blogdate, content
                FROM blog
                WHERE MATCH(content) AGAINST('$c')
                AND id <> '$id'
                ORDER BY blogdate DESC";
        $res = mysql_query($sql) or die (mysql_error()."<p>$sql</p>");
        while (list ($d, $c) = mysql_fetch_row($res))
        {
            echo '<b>', date('jS F', strtotime($d)), '</b><br>', $c, '<br><br>';
        }
        echo '<hr>';
    }
}
?>
<form>
Select a blog record (1-6)
<input type='text' name='id' size='4'>
<input type='submit' name='action' value='Submit'>
</form>


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.