EternalSorrow Posted January 11, 2009 Share Posted January 11, 2009 I recently acquired a tag cloud code from Prism Perfect for use with the simple article database I created. I have two tables the tag must query: The catjoin table holds category_id and entry_id. It is used to show the COUNT for instances of category use per entry_id. The category table holds category_id and the actual category_name. The creator stated that one could use two tables, but I've found that when joining the two tables the category_name from category, which is the second table, isn't queried. Only an empty space appears where the $category_name should be. I've tried using variations in the SELECT area and WHILE area, but either it doesn't work or I receive an error message concerning the ARRAYs. Here's the code I slightly modified for my own use: <?php mysql_connect(localhost,user,pw); @mysql_select_db(db) or die( "Unable to select database"); $query = "SELECT category_id AS tag, COUNT(entry_id) AS quantity FROM catjoin JOIN category USING (category_id) GROUP BY category_id ORDER BY category_id ASC"; $result = mysql_query($query); while ($row = mysql_fetch_array($result)) { $tags[$row['tag']] = $row['quantity']; } $max_size = 250; // max font size in % $min_size = 100; // min font size in % $max_qty = max(array_values($tags)); $min_qty = min(array_values($tags)); $spread = $max_qty - $min_qty; if (0 == $spread) { // we don't want to divide by zero $spread = 1; } $step = ($max_size - $min_size)/($spread); foreach ($tags as $key => $value) { $size = $min_size + (($value - $min_qty) * $step); echo '<a href="categories.php?category_name='.$category_name.'" style="font-size: '.$size.'%"'; echo ' title="'.$value.' article(s) tagged with '.$key.'"'; echo '>'.$category_name.'</a> '; } ?> Quote Link to comment Share on other sites More sharing options...
killah Posted January 11, 2009 Share Posted January 11, 2009 Try this as your first query: $Query = sprintf (' SELECT c.*,ci.* FROM c.category LEFT JOIN ci.catjoin USING (c.category_id) GROUP BY c.category_id ORDER BY c.category_id ASC '); $result = mysql_query($Query) or die("Line error on " . ___LINE___ . "<br>".mysql_error()); Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted January 11, 2009 Author Share Posted January 11, 2009 It merely gives the following error message: Line error on ___LINE___ You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '.category_id) GROUP BY c.category_id ORDER BY c.category_id ASC' at line 2 Quote Link to comment Share on other sites More sharing options...
killah Posted January 11, 2009 Share Posted January 11, 2009 $Query = sprintf (" SELECT c.*,ci.* FROM c.category LEFT JOIN ci.catjoin USING (c.category_id) ORDER BY c.category_id ASC GROUP BY c.category_ID "); $result = mysql_query($Query) or die(mysql_error().'<br><br><b>Query Was:</b><br>".$Query); Quote Link to comment Share on other sites More sharing options...
EternalSorrow Posted January 11, 2009 Author Share Posted January 11, 2009 The error message remains the same. Here's the modified Query code in full (I've placed a simple "or die" command in the result line): $Query = sprintf ("SELECT c.*, ci.* FROM c.category LEFT JOIN ci.catjoin USING (c.category_id) GROUP BY c.category_id ORDER BY c.category_id ASC"); $result = mysql_query($Query) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.