Heath Posted May 16, 2007 Share Posted May 16, 2007 Right now I this code in order to show the menu based on size... here is the code. <?php function printTagCloud($tags) { // $tags is the array arsort($tags); $max_size = 32; // max font size in pixels $min_size = 12; // min font size in pixels // 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 ($spread == 2) { // we don't want to divide by zero $spread = 1; } // set the font-size increment $step = ($max_size - $min_size) / ($spread); // loop through the tag array foreach ($tags as $key => $value) { // calculate font-size // find the $value in excess of $min_qty // multiply by the font-size increment ($size) // and add the $min_size set above $size = round($min_size + (($value - $min_qty) * $step)); echo '<a href="#" style="font-size: ' . $size . 'px" title="' . $value . ' things tagged with ' . $key . '">' . $key . '</a> '; } } $tags = array('weddings' => 32, 'birthdays' => 9, 'landscapes' => 62, 'ham' => 51, 'chicken' => 23, 'food' => 9, 'turkey' => 47, 'windows' => 82, 'apple' => 27); printTagCloud($tags); ?> What I want to do is have those numbers that correspond with the menu item to change every time it is clicked so the most clicked item will always remain the largest. Can some one give me a little help on how to accomplish that? I would prefer to not use the database for this, but if needed then I am open to ideas. As long as it is not a security issue. Thank you. This sites great! Quote Link to comment https://forums.phpfreaks.com/topic/51588-creating-a-php-menu-that-changes-text-size-per-click/ Share on other sites More sharing options...
phast1 Posted May 16, 2007 Share Posted May 16, 2007 If you are wanting the text size to change based on the number of times that each item has been clicked, then I see no way of accomplishing this without saving the data somewhere, such as a database or flat text file.. Using a database is definitely the preferred method, but a flat file would work if you didn't have database access.. Using a database is not a security issue, especially if you are not storing sensitive information (such as personal info).. Anyhow, once you decide where to store the information, you would just need to add some code to each page that corresponds to a menu item, so that each visit to that page would increment a counter specifically for that page.. After that, you would just change this line in your code to load the data dynamically from the database (or file) instead of hard coding the values: $tags = array('weddings' => 32, 'birthdays' => 9, 'landscapes' => 62, 'ham' => 51, 'chicken' => 23, 'food' => 9, 'turkey' => 47, 'windows' => 82, 'apple' => 27); Quote Link to comment https://forums.phpfreaks.com/topic/51588-creating-a-php-menu-that-changes-text-size-per-click/#findComment-254185 Share on other sites More sharing options...
Heath Posted May 16, 2007 Author Share Posted May 16, 2007 any way you could help me out with a simple code to accomplish that? I have been searching for some sort of link tracker all day and they keep coming up as large programs. Even a tutorial link would help greatly. Im having a hard problem finding one. I kind of thought that might be the case, doing it with the database instead, but any help you could provide would be much appreciated, between trying to do this and implement a clip dump in my site im driving myself crazy because neither are coming together :-( so thank you I greatly appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/51588-creating-a-php-menu-that-changes-text-size-per-click/#findComment-254293 Share on other sites More sharing options...
Heath Posted May 16, 2007 Author Share Posted May 16, 2007 any one? please? Quote Link to comment https://forums.phpfreaks.com/topic/51588-creating-a-php-menu-that-changes-text-size-per-click/#findComment-254730 Share on other sites More sharing options...
phast1 Posted May 17, 2007 Share Posted May 17, 2007 You need to add code to the destination pages that will increment counters that are stored in the database.. So, if you have a menu.php that displays the menu and then separate pages that people are clicking to, such as page1.php, page2.php, etc, then you would need to modify the page*.php file and add code that does an update on an integer field in the database to increment by 1 each time that page is loaded.. You will basically end up with a mySQL table like this: id page1 page2 page3 etc and each of those fields will store an integer count for how many times that page has been accessed.. Once you have that accomplished, then you would need to modify your menu.php page to select the counter data from the database and use that instead of hard-coded numbers.. Such as: $result = mysql_query('SELECT * FROM counters'); if (!$result) { $message = 'Invalid query: ' . mysql_error() . "\n"; $message .= 'Whole query: ' . $query; die($message); } $row = mysql_fetch_assoc($result); $tags = array('weddings' => $row['page1'], 'birthdays' => $row['page2'], 'landscapes' => $row['page3'], 'ham' => $row['page4'], 'chicken' => $row['page5'], 'food' => $row['page6'], 'turkey' => $row['page7'], 'windows' => $row['page8'], 'apple' => $row['page9']); printTagCloud($tags); Quote Link to comment https://forums.phpfreaks.com/topic/51588-creating-a-php-menu-that-changes-text-size-per-click/#findComment-255863 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.