Jump to content

get similar posts


doddsey_65

Recommended Posts

im trying to run a query which will get posts from the database that have tags similar to the current ones.

Unfortunatly the echoed result isnt displaying as it should.

 

$query = $link->query("SELECT t.*, p.* 
                                FROM ".TBL_PREFIX."topics t
                                JOIN ".TBL_PREFIX."posts p
                                ON (p.p_tid = t.t_tid)
                                WHERE t.t_name = '".decode_url($_GET['t_name'])."'
                                LIMIT 1")
                                or die(print_link_error());
            $row = $query->fetch(PDO::FETCH_ASSOC);
            
            $tag_query = $link->query("SELECT p_name
                                    FROM ".TBL_PREFIX."posts
                                    WHERE MATCH (p_tags) 
                                    AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE)
                                    ")or die(print_link_error());
            $result = $tag_query->fetch();
            
            foreach($result as $key => $value)
            {
                echo 'Name = '.$result[$key]['p_name'].'<br />';
            }

 

i have done a dump of result and it shows:

 

$ => Array (2)
(
    ['p_name'] = String(12) "File Updates"
    ['0'] = String(12) "File Updates"
)

 

but there should only be one item in this array(p_name).

I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right.

 

Link to comment
https://forums.phpfreaks.com/topic/237454-get-similar-posts/
Share on other sites

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.