Jump to content

results from db query and array_count_values


Scip

Recommended Posts

Ok i have a result from a database query which i am using array_count_values to count the number of times a value is repeat in the array.

 

The problem is it returns twice the number of expected values.

 

here is some code:

  <?php
    $query = "SELECT ";
    $query .= "item1, item2, item3, item4, item5, item6, item7, item8, item9, item10 ";
    $query .= "FROM loot ";
    $query .= "WHERE ";
    $query .= "Date < NOW() ";
    $query .= "AND Date > DATE_ADD(NOW(), INTERVAL -1 MONTH)";
    
    $result = mysql_query($query,$connection);
    confirm_query($result);
    $loot = mysql_fetch_array($result);
    
    
    if($loot){

   echo count($loot) ."<br/>";
   $requests = array_count_values($loot);
   
   print_r($requests);

    }else{
$message = "An error occured with the query.";
    }

?>

 

each item in the database should only have one value so array_count_values should return a value of one for each of item1 to 10.  but it's return a value of two for each. Also an echo of loot should only return a value of 10 since i am only select 10 items from the database but it's 20.

 

here is the output from the above code:

20
Array ( [Ebonite] => 2 [Aluminite] => 2 [Kobalit] => 2 [Dragoturkey Peak] => 2 [bear Bone] => 2 [black Dragoss Horn] => 2 [ice Kwak Beak] => 2 [Dragoturkey] => 2 [barley] => 2 [barley Sugar] => 2 )

 

I tried commenting everything from "WHERE" onwards from the query statement but i still get the same results.

 

any help is apperiacted. thanks

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.