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
$q = dq("select * FROM $table WHERE keywords LIKE '$keywords' ORDER BY hits LIMIT 10",1); PHP: Will match exact 'keywords' and not 'keyword'
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:
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
$q = dq("select * from $table where keywords = '$keywords' order by hits limit 4",1); I hope this one works