webweever Posted December 4, 2007 Share Posted December 4, 2007 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? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 I don't see the population of $category_id[] thus it is always returning blank Quote Link to comment Share on other sites More sharing options...
webweever Posted December 4, 2007 Author Share Posted December 4, 2007 Where in the code would I put that? Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 its your variable define it where you want Quote Link to comment Share on other sites More sharing options...
webweever Posted December 4, 2007 Author Share Posted December 4, 2007 If I place this: $category_id[$row['id']] Here: $tags[$row['tag']] = $row['quantity']; $category_id[$row['id']]; I still get no links. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 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> '; } ?> Quote Link to comment Share on other sites More sharing options...
webweever Posted December 4, 2007 Author Share Posted December 4, 2007 Now I get this error 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 Quote Link to comment Share on other sites More sharing options...
webweever Posted December 4, 2007 Author Share Posted December 4, 2007 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. Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 cause u didn't listen to what I said you need to replace PRIMARY KEY with your table's primary key. Quote Link to comment Share on other sites More sharing options...
webweever Posted December 4, 2007 Author Share Posted December 4, 2007 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']; } Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted December 4, 2007 Share Posted December 4, 2007 your selecting the actual field name as something else select REAL FIELD NAME as Somethign else you did it backwards. 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.