Jump to content

count array help


alohatofu

Recommended Posts

Hello,

 

I'm wondering if any mysql masters out there can help me with this.

I'm trying to query the number of instances that the same value occur in a field in the last 90 days.  Say that my field is called clli from table surv_item and the date let's call it $creation_date

 

How would I do that?

 


$query = "SELECT clli FROM surv_item";
$result = mysql_query($query);
while ( $row = mysql_fetch_array($result))
{
extract($row);
$clli[] = $clli;
}
$output = array_count_values($clli);

 

that doesn't seem to work.  I'm very new to mySQL.

 

Thank you

Link to comment
https://forums.phpfreaks.com/topic/47369-count-array-help/
Share on other sites

 

you are using the same name for array variable and the table col.

Just change the name of array and try. it is working for me, should work for you also.

 

$query = "SELECT clli FROM surv_item";

$result = mysql_query($query);

while ( $row = mysql_fetch_array($result))

{

extract($row);

$tmp[] = $clli;

}

$output = array_count_values($tmp);

print_r($output);

 

output:

 

Array ( [1] => 3 [2] => 1 [3] => 1 [5] => 2 [10] => 1 )

 

 

I tested it for strings and numbers.

 

-SunilKumar

Link to comment
https://forums.phpfreaks.com/topic/47369-count-array-help/#findComment-231117
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.