int phrase_length = 2;
int key_length = strkey.Length;
string strsubkey = "";
string strnew = "";
if (key_length > 1)
{
for (int i = 0; i < key_length - phrase_length + 1; i++)
{
strsubkey = strkey.Substring(i, phrase_length);
strnew += " OR title LIKE '%" + strsubkey + "%'";
}
}
string strSql = "SELECT TOP 8 id, title, uid, post_time FROM [V6bbs_bbs] WHERE parent_id=0 AND is_del=0 AND title<>'" + strkey + "' AND (title LIKE '%" + strkey + "%'" + strnew + ") ORDER BY id DESC";
用基于简单模式匹配的字符串比较功能实现.
具体一点,比如,你现有的讨论主题或包含的关键字是AAA,则你可以在写如下SQL语句来实现:
select B from C where B like '%AAA%' and B<>'AAA' 其中,B表示关键字或主题,C是你存放帖子相关信息的表.
按你的意思是这样了.