Jump to content

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>


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.