Jump to content

Tag Cloud - two tables problem


EternalSorrow

Recommended Posts

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> ';

}
?>

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

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());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.