计算一些有限的单词,并显示它们对应于他们的名字 [英] count some limited words and display them correspond to their names

查看:63
本文介绍了计算一些有限的单词,并显示它们对应于他们的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用搜索框从标题中搜索用户输入。除此之外,我想从另一列主题中计算一些关键词,仅在标题栏中的用户输入对应。但问题是如何查找我在查询中提到的单词的数量,即



标题        Subject



a        word1,word2,word1,

ab        word2,word4,word3,

bb       word1,word4,word4,

aa        word2,word2,word4,

cb       word1,word1,word3,

ac        word2,word1,word3,

所以,如果我在文本框中搜索过,那么,如何从主题中获取word1的数量,其中只有a是出现在标题字段中,然后类似于其他单词,以便我可以获得如下输出:



您的搜索包含:

word1 (3)

word2(5)

word3(2)

word4(2)

代码查询如下:

I am using a search box that searches the user input from "title". Besides this i want to count some keywords from another column "subject" only in the presense of user input corresponds in "title" column. but the problem is that how to find count of only words i have mentioned in the query i.e.

Title       Subject

a       word1,word2,word1,
ab      word2,word4,word3,
bb      word1,word4,word4,
aa      word2,word2,word4,
cb      word1,word1,word3,
ac      word2,word1,word3,
So, here if i have searched for a in textbox then, how can i get count of word1 from subject where only a is present in the title field and then similar for the other words so that i could get output like:

your search a contains :
word1 (3)
word2 (5)
word3 (2)
word4 (2)
The code for query is given below:

<pre lang="xml">$getq = "SELECT Title,Subject COUNT(*) FROM tablename WHERE Title LIKE '%$search_each%' Subject LIKE '%word1%' OR Subject LIKE '%word2%' OR Subject LIKE '%word3%' OR Subject LIKE '%word4%') GROUP BY Subject";
$getquery = $conn->query($getq);
while( $runrows = mysqli_fetch_assoc($getquery))
{
$sub = $runrows ['Subject'];
$countsub = $runrows ['COUNT(*)'];
}
echo "<a href='#'>"word1"(".$countsub.")</a> ";
echo "<a href='#'>"word2"(".$countsub.")</a> ";
echo "<a href='#'>"word3"(".$countsub.")</a> ";
echo "<a href='#'>"word4"(".$countsub.")</a> ";</pre>



这里,$ search_each是文本框输入,上面的代码显示没有代替$ countub,因为我不知道如何根据用户搜索词的预设获得所有单词的个人计数。如何做到这一点?



我们将非常感谢您的帮助。


Here, $search_each is textbox input and the above code shows nothing in place of $countsub because i don't know how to get individual count for all words under presense of user's search term. How this can be done?.

Your help will be highly appreciated.

推荐答案

getq = SELECT Title,Subject COUNT(*)FROM tablename WHERE Title LIKE'%
getq = "SELECT Title,Subject COUNT(*) FROM tablename WHERE Title LIKE '%


search_each%'Subject LIKE'%word1%'或Subject LIKE'%word2%'或Subject LIKE'%word3 %'或主题LIKE'%word4%')GROUP BY主题;
search_each%' Subject LIKE '%word1%' OR Subject LIKE '%word2%' OR Subject LIKE '%word3%' OR Subject LIKE '%word4%') GROUP BY Subject";


getquery =
getquery =


这篇关于计算一些有限的单词,并显示它们对应于他们的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆