Visualizzazione dei risultati da 1 a 3 su 3

Discussione: tag clud

  1. #1

    tag clud

    Ragazzi ho questo script per la tag cloud che non funziona ma non capisco qual'è il problema:

    codice è questo


    Codice PHP:

    <?php

    // Define user variables
    $fontSizeUnit "px";
    $maxFontSize 50;
    $minFontSize 12;
    $tagsToDisplay 50;
    $tagDivider "/"// Leave blank for none

    // Calculations
    $fontSizeSpread $maxFontSize $minFontSize;

    // Create a few blank arrays
    $tagArray = array();
    $tempTagArray = array();

    // Connect to and query mySQL Database (NOTE: change "hostname," "username,"
    // "password," and "databasename" to your information)
    include ('config.php');
    // Get all rows that don't have blank tags (NOTE: change "tablename" to your table)
    $result mysql_query("SELECT * FROM tag_tbiz WHERE tag!=''");

    // Loop through each result of the query
    while($row mysql_fetch_array($result)){

        
    // Split the result of each query ", " (our tags will be in the form "tag 1,
        // tag 2, tag 3" etc.) and store the results to an array
        
    $tempStringArray preg_split("/, /"$row["tag"]);

        
    // Loop through all items of this string array (i.e. loop through each tag)
        // Use a "for" loop
        
    for ($a 0$a count($tempStringArray); $a++) {
             
    // Convert to lowercase
             
    $tempStringArray[$a] = strtolower($tempStringArray[$a]);
             
    // Check if it exists in tag array
             
    if ($tagArray[$tempStringArray[$a]] == '') {
                 
    // If it doesn't exist, create it with value 1
                 
    $tagArray[$tempStringArray[$a]] = 1;
             } else {
                 
    // If it does exist, increase the value by 1
                 
    $tagArray[$tempStringArray[$a]] += 1;
             }
         }
    }
    // Store to temporary array to be used to choose the top tags, then sort
    // temporary array according to tag value, descending
    arsort($tagArray);
    $numberOfTags 0;
    foreach (
    $tagArray as $key => $val) {
        
    $numberOfTags++;

        if (
    $numberOfTags $tagsToDisplay) {
            break;
        }

        
    $finalTagArray[$key] = $val;
    }
    ksort($finalTagArray);

    $maxTagCount max($finalTagArray);
    $minTagCount min($finalTagArray);

    $tagCountSpread $maxTagCount $minTagCount;

    $unitsPerCount $fontSizeSpread/$tagCountSpread;

    // Function to calculate the font size
    function calcSize($thisTagCount) {

        
    // Import necessary global variables
        
    global $minTagCount$minFontSize$fontSizeUnit$unitsPerCount;

        
    // Calculate the font size
        
    $thisFontSize $minFontSize+($unitsPerCount*($thisTagCount-$minTagCount));

        
    // Round the font size and add units
        
    $thisFontSize round($thisFontSize) . $fontSizeUnit;

        
    // Return the font size
        
    return $thisFontSize;

    }

    $b 1;
    foreach (
    $finalTagArray as $key => $val) {
        echo 
    "<span style='font-size: ";
            echo 
    calcSize($val);
            echo 
    "'>" $key "</span>";
        if (
    $b != count($finalTagArray)) {
            echo 
    " " $tagDivider " ";
        }
        
    $b++;
    }

    ?>
    l'errore che mi da è :

    Warning: Division by zero in /web/htdocs/technologybiz.eu/home/prova2.php on line 65

    corrispondente a questo:

    $unitsPerCount = $fontSizeSpread/$tagCountSpread;


    ringrazio in anticipo per l'aiuto

  2. #2
    se $tagCountSpread = 0 la divisione è impossibile. Se non è normale che $tagCountSpread sia uguale a 0 allora il problema è da un'altra parte, altrimenti devi mettere un if per gestire il caso che $tagCountSpread = 0
    IP-PBX management: http://www.easypbx.it

    Old account: 2126 messages
    Oldest account: 3559 messages

  3. #3
    Estrae i dati da una tabella che contiene 90 tag, non è possibile che sia vuoto non riesco a capire perchè non funziona, non mette neanche alcune parole più grandi .. mi sta facendo perdere la testa

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.