Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [MySQL][PHP] Generowanie Chmury Tagów...
siwybob
post
Post #1





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 8.07.2009

Ostrzeżenie: (0%)
-----


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...
Go to the top of the page
+Quote Post
nospor
post
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




  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. }


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
siwybob
post
Post #3





Grupa: Zarejestrowani
Postów: 12
Pomógł: 0
Dołączył: 8.07.2009

Ostrzeżenie: (0%)
-----


dzięki, o tą linijkę mi chodziło... smile.gif
pzd
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 21.08.2025 - 12:09