Chotor Posted May 22, 2008 Share Posted May 22, 2008 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. Link to comment https://forums.phpfreaks.com/topic/106739-solved-something-funny-going-on-with-my-arrays/ Share on other sites More sharing options...
Chotor Posted May 22, 2008 Author Share Posted May 22, 2008 To rephrase: Why is one array showing results and the other is showing no results, even though they recieve the same input?? Even stranger, the "empty" array still has 55 elements... Link to comment https://forums.phpfreaks.com/topic/106739-solved-something-funny-going-on-with-my-arrays/#findComment-547400 Share on other sites More sharing options...
Chotor Posted May 22, 2008 Author Share Posted May 22, 2008 Ok. Got it. A small, almost invisible '}' had sneaked in, and made all my "echo" and "var_dump" reside inside the 'if' that never was true. Please disregard this thread. Link to comment https://forums.phpfreaks.com/topic/106739-solved-something-funny-going-on-with-my-arrays/#findComment-547413 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.