72newbie
07-01-2009, 01:12 AM
I'm looking for a fast lightweight way to count the results from a search.
this is what I have that seems to work:
$arr = array(11,22,33,11,22,33,44,55555,666666,666666);
foreach ($arr as $key => $word )
{
$words[] = $word;
}
$count = array_count_values($words);
foreach ($count as $key => $value)
{
echo "Number of occurrences:<b> $value </b>of word: <b>$key</b><br>\n";
}
but when I try to add a query into it it does not work...?
$id = "SELECT category_id FROM items ".$where_query." GROUP BY category_id DESC LIMIT 0,15";
$result = mysql_query($id) or die(mysql_error());
while($row = array($result))
{
foreach ($row['category_id'] as $key => $word )
{
$words[] = $word;
}
$count = array_count_values($words);
foreach ($count as $key => $value)
{
echo "Number of occurrences:<b> $value </b>of word: <b>$key</b><br>\n";
}
}
somehow i need to find the number of unique rows?
I am thinking maybe in this part is where i'm going wrong but i've been trying for days and I have to ask for help on this.
$result = mysql_query($id) or die(mysql_error());
while($row = array($result))
this is what I have that seems to work:
$arr = array(11,22,33,11,22,33,44,55555,666666,666666);
foreach ($arr as $key => $word )
{
$words[] = $word;
}
$count = array_count_values($words);
foreach ($count as $key => $value)
{
echo "Number of occurrences:<b> $value </b>of word: <b>$key</b><br>\n";
}
but when I try to add a query into it it does not work...?
$id = "SELECT category_id FROM items ".$where_query." GROUP BY category_id DESC LIMIT 0,15";
$result = mysql_query($id) or die(mysql_error());
while($row = array($result))
{
foreach ($row['category_id'] as $key => $word )
{
$words[] = $word;
}
$count = array_count_values($words);
foreach ($count as $key => $value)
{
echo "Number of occurrences:<b> $value </b>of word: <b>$key</b><br>\n";
}
}
somehow i need to find the number of unique rows?
I am thinking maybe in this part is where i'm going wrong but i've been trying for days and I have to ask for help on this.
$result = mysql_query($id) or die(mysql_error());
while($row = array($result))