Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [MySQL][PHP] Generowanie Chmury Tagów...
Forum PHP.pl > Forum > Przedszkole
siwybob
Witam,
Próbuje sobie wyświetlić chmurkę tagów, przy pomocy znaalezionej w necie funkcji:


  1. <?php
  2. function printTagCloud2($tags) {
  3. // $tags is the array
  4.  
  5. arsort($tags);
  6.  
  7. $max_size = 32; // max font size in pixels
  8. $min_size = 12; // min font size in pixels
  9.  
  10. // largest and smallest array values
  11. $max_qty = max(array_values($tags));
  12. $min_qty = min(array_values($tags));
  13.  
  14. // find the range of values
  15. $spread = $max_qty - $min_qty;
  16. if ($spread == 0) { // we don't want to divide by zero
  17. $spread = 1;
  18. }
  19.  
  20. // set the font-size increment
  21. $step = ($max_size - $min_size) / ($spread);
  22.  
  23. // loop through the tag array
  24. foreach ($tags as $key => $value) {
  25. // calculate font-size
  26. // find the $value in excess of $min_qty
  27. // multiply by the font-size increment ($size)
  28. // and add the $min_size set above
  29. $size = round($min_size + (($value - $min_qty) * $step));
  30.  
  31. echo '<a href="#" style="font-size: ' . $size . 'px" title="' . $value . ' things tagged with ' . $key . '">' . $key . '</a> ';
  32. }
  33. }



Tagi mam w bazie, wyciągając je:


  1. (...)
  2. $result1 = mysql_query("SELECT * FROM tags");
  3.  
  4.  
  5. while ($row1 = mysql_fetch_array($result1)) {
  6. $title = $row1[title];
  7. $counter = $row1[counter];
  8.  
  9. $tags[] = array($title => $counter);
  10.  
  11. }
  12. (...)



no i próbuje:

  1. printTagCloud2($tags);


no i lipa.

Mam problem z tą tablicą:

powinna mieć formę

  1. $tags = array('weddings' => 32, 'birthdays' => 41, 'landscapes' => 62, 'ham' => 51, 'chicken' => 23, 'food' => 91, 'turkey' => 47, 'windows' => 82, 'apple' => 27);


a to moje "pobranie" daje:

  1. (
  2. [0] => Array
  3. (
  4. [aktorka] => 21
  5. )
  6.  
  7. [1] => Array
  8. (
  9. [film] => 1
  10. )
  11.  
  12. [2] => Array
  13. (
  14. [kino] => 1
  15. )
  16.  
  17. [3] => Array
  18. (
  19. [seriale] => 5
  20. )
  21.  
  22. [4] => Array
  23. (
  24. [widoki] => 3
  25. )
  26.  
  27. [5] => Array
  28. (
  29. [zabawne] => 4
  30. )
  31.  
  32. )


Nie za bardzo łapię tą tablice... Może ktoś podpowie...?
Dzieki za help...
nospor
  1. $tags = array();
  2. while ($row1 = mysql_fetch_array($result1)) {
  3. $title = $row1[title];
  4. $counter = $row1[counter];
  5.  
  6. $tags[$title] = $counter;
  7.  
  8. }
siwybob
dzięki, o tą linijkę mi chodziło... smile.gif
pzd
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.