How Find Related Posts from text field of table?

Discussion in 'PHP' started by earngate, Nov 23, 2010.

  1. #1
    Hello,
    we have posts table contain :
    id,title,description,keywords,username,hits,comments

    we want create sql command to get Related posts by keywords
    but keywords field type is text " more than 1 keywords "

    how we can do that ???


    we tried to use this code
    
    function more_items_keywords($what,$keywords,$html) {
    global $s,$m;
    if ($html) $function_name = 'A_parse_part'; else $function_name = 'parse_part';
    $where = get_where_fixed_part('',0,0,$s[cas]);$s[more_items_list]=10;
    $table = $s[item_types_tables][$what];
    $q = dq("select * from $table where keywords = '$keywords' order by hits limit 10",1);
    while ($x = mysql_fetch_assoc($q)) $items[] = '<a href="'.get_detail_page_url($what,$x[n],$x[rewrite_url],'',5).'">'.$x[title].'</a>';
    if ($items[0])
    { //$a[items] = implode('<br />',$items);
      //$a[title] = $m['more_'.$what];
      return implode('<tr><td class="posts" align="right">',$items);
    }
    }
    
    
    PHP:
    it's extract related posts if keywords field have 1 keyword only !!!

    can you help
     
    earngate, Nov 23, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    
    $q = dq("select * FROM $table WHERE keywords LIKE '$keywords' ORDER BY hits LIMIT 10",1);
    
    PHP:
    Will match exact 'keywords' and not 'keyword'
     
    MyVodaFone, Nov 23, 2010 IP
  3. ZoomRumble

    ZoomRumble Peon

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This should works for more then one keywords

    function more_items_keywords($what,$keywords,$html)
    {
        global $s,$m;
        if ($html) $function_name = 'A_parse_part'; else $function_name = 'parse_part';
        $where = get_where_fixed_part('',0,0,$s[cas]);
        $s[more_items_list]=10;
        $table = $s[item_types_tables][$what];
        $arr = explode(" ", $keywords);
        $keyword = implode("' OR keywords = '", $arr);
        $q = dq("select * from $table where keywords = '$keywords' order by hits limit 10",1);
        while ($x = mysql_fetch_assoc($q)) $items[] = '<a href="'.get_detail_page_url($what,$x[n],$x[rewrite_url],'',5).'">'.$x[title].'</a>';
        if ($items[0])
        { //$a[items] = implode('<br />',$items);
            //$a[title] = $m['more_'.$what];
            return implode('<tr><td class="posts" align="right">',$items);
        }
    }
    PHP:
     
    ZoomRumble, Nov 23, 2010 IP
  4. earngate

    earngate Well-Known Member

    Messages:
    102
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #4
    Thanks
    MyVodaFone and ZoomRumble for help
    but codes not work

    how we can Select only first four lines, from Sql text field ?
    this may resolve problem
     
    earngate, Nov 26, 2010 IP
  5. drctaccess

    drctaccess Peon

    Messages:
    62
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #5
    $q = dq("select * from $table where keywords = '$keywords' order by hits limit 4",1);

    I hope this one works
     
    drctaccess, Nov 27, 2010 IP