searching array of words faster
Posted
by
Martijn
on Stack Overflow
See other posts from Stack Overflow
or by Martijn
Published on 2011-01-13T22:43:28Z
Indexed on
2011/01/13
22:53 UTC
Read the original article
Hit count: 147
hi eveybody
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.
© Stack Overflow or respective owner