Jump to content

[SOLVED] Something funny going on with my arrays...


Chotor

Recommended Posts

I'm trying to make a tag cloud.

 

I have the following code where 'query2' yields a normal string->string array. But 'query2' yields an empty array with 55 elements!?

What's going on??

$query1 = "SELECT `keyword` AS tag, COUNT(movie_id) AS quantity
FROM keyword_map
JOIN keywords ON (keywords.keyword_id = keyword_map.keyword_id)
GROUP BY keyword
ORDER BY quantity DESC";

$query2 = "SELECT keyword AS tag, COUNT(keyword_id) AS quantity
FROM keywords
GROUP BY keyword
ORDER BY keyword ASC";

$result = $link->query($query2); //query1 or query2
echo "Number of rows: ".$result->num_rows; // will show '55' in both cases
while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
     $tags[$row['tag']] = $row['quantity'];
   //echo "tags: ".$row['tag']."->".$row['quantity']."<br>";  // <-- I've been using this to see what's going on
}

echo "Length: ".count($tags); //<-- shows '55' in both cases (!)

var_dump($tags); // shows the array for 'query2'. No output for 'query1'.. just nothing..

 

My 'echo' within the 'while' reveals nothing strange going on. Every value is as expected.

I've been scrutinizing this, but cannot figure out what's going on.

 

 

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.