更快地搜索单词数组
我想看看数据库中有多少数组。它非常慢,我想知道是否有一种方法可以在没有 for 循环的情况下搜索多个单词或整个数组。我现在正在挣扎一段时间。
这是我的代码,
$dateBegin = "2010-12-07 15:54:24.0";
$dateEnd = "2010-12-30 18:19:52.0";
$textPerson = " text text text text text text text text text text text text text text ";
$textPersonExplode = explode(" ", $textPerson );
$db = dbConnect();
for ( $counter = 0;$counter <= sizeof($textPersonExplode)-1 ; $counter++) {
$query = "SELECT count(word) FROM `news_google_split` WHERE `word` LIKE '$textPersonExplode[$counter]' AND `date` >= '$dateBegin' AND `date` <= '$dateEnd'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$word[] = $textPersonExplode[$counter];
$count[] = $row[0];
}
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
感谢您的帮助。
i want to look how much an array comes in a database. Its pretty slow and i want to know if there's a way of searching like multiple words or an whole array without a for loop.. i'm struggeling for a while now.
here's my code
$dateBegin = "2010-12-07 15:54:24.0";
$dateEnd = "2010-12-30 18:19:52.0";
$textPerson = " text text text text text text text text text text text text text text ";
$textPersonExplode = explode(" ", $textPerson );
$db = dbConnect();
for ( $counter = 0;$counter <= sizeof($textPersonExplode)-1 ; $counter++) {
$query = "SELECT count(word) FROM `news_google_split` WHERE `word` LIKE '$textPersonExplode[$counter]' AND `date` >= '$dateBegin' AND `date` <= '$dateEnd'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$word[] = $textPersonExplode[$counter];
$count[] = $row[0];
}
if (!$result) {
die('Invalid query: ' . mysql_error());
}
}
thanks for the help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果在查询中使用 MATCH..AGAINST 对,则可以避免 for 循环。 IE:
You can avoid the for loop if you use MATCH..AGAINST pair in your query. i.e:
查看全文索引。
Check out full text indexing.
我们在 Db 中发送一个逗号分隔的列表,然后将该列表转换为一个表,然后我们在查询中以联接的形式使用该表。
但是,您需要确保可以传入多少数据作为查询或存储过程的输入。
We send a comma seperated list in Db, then converted that list into a table, then we used that table in our queries in the form of joins.
However you need to make sure how much data you can pass in as the input of the query or stored procedure.