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开发者_如何学Python 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.
You can avoid the for loop if you use MATCH..AGAINST pair in your query. i.e:
$query = "SELECT count(word) FROM `news_google_split` WHERE MATCH(`word`) AGAINST
('$textPerson') AND `date` >= '$dateBegin' AND `date` <= '$dateEnd'";
Check out full text indexing.
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.
精彩评论