Jump to content

Linkable Tagcloud


webweever

Recommended Posts

I have a tagcloud with the code below, it creates to cloud ok and makes the text linkable but it links to nothing. Links come out like this index.php?cat_id=.

 

$query = "SELECT cat AS tag, COUNT(id) AS quantity
  FROM bookmarks
  GROUP BY cat
  ORDER BY cat ASC";

$result = mysql_query($query);

// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
while ($row = mysql_fetch_array($result)) {

    $tags[$row['tag']] = $row['quantity'];
}

// change these font sizes if you will
$max_size = 120; // max font size in %
$min_size = 75; // min font size in %

// get the largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

// find the range of values
$spread = $max_qty - $min_qty;
if (0 == $spread) { // we don't want to divide by zero
    $spread = 1;
}

// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);

// loop through our tag array
foreach ($tags as $key => $value) {

    $size = $min_size + (($value - $min_qty) * $step);

    echo '<a href="index.php?cat_id='.$category_id[$key].'"
      style="font-size: '.$size.'%"
      title="'.$value.' things tagged with '.$key.'">'
      .$key.'</a> ';
}

 

How do I make the links link to the particular id for each tag?

Link to comment
Share on other sites

try:  (you aren't selecting the ID in your query thus the issue  (Replace PRIMARY KEY with the Primary Key)

<?Php
$query = "SELECT cat AS tag, COUNT(id) AS quantity, PRIMARY KEY AS PK
  FROM bookmarks
  GROUP BY cat
  ORDER BY cat ASC";

$result = mysql_query($query) or die (mysql_error());

// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
while ($row = mysql_fetch_array($result)) {

    $tags[$row['PK']] = $row['quantity'];

}

// change these font sizes if you will
$max_size = 120; // max font size in %
$min_size = 75; // min font size in %

// get the largest and smallest array values
$max_qty = max(array_values($tags));
$min_qty = min(array_values($tags));

// find the range of values
$spread = $max_qty - $min_qty;
if (0 == $spread) { // we don't want to divide by zero
    $spread = 1;
}

// determine the font-size increment
// this is the increase per tag quantity (times used)
$step = ($max_size - $min_size)/($spread);

// loop through our tag array
foreach ($tags as $key => $value) {

    $size = $min_size + (($value - $min_qty) * $step);

    echo '<a href="index.php?cat_id='.$category_id[$key].'"
      style="font-size: '.$size.'%"
      title="'.$value.' things tagged with '.$key.'">'
      .$key.'</a> ';
}
?>

Link to comment
Share on other sites

Anyone have any idea what this error is about?

 

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 'PRIMARY KEY AS PK FROM bookmarks GROUP BY cat ORDER BY

 

I've looked at the MySQL manual and tried:

 

PRIMARY KEY AS PK

PRIMARY KEY PK

PRIMARY KEY (PK)

 

All error out as a syntax error.

Link to comment
Share on other sites

I did use my DBs Primary Key (id).

 

$query = "SELECT cat AS tag, COUNT(id) AS quantity, PRIMARY KEY AS id
  FROM bookmarks
  GROUP BY cat
  ORDER BY cat ASC";

$result = mysql_query($query) or die (mysql_error());

// here we loop through the results and put them into a simple array:
// $tag['thing1'] = 12;
// $tag['thing2'] = 25;
// etc. so we can use all the nifty array functions
// to calculate the font-size of each tag
while ($row = mysql_fetch_array($result)) {

    $tags[$row['id']] = $row['quantity'];

}

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.