Why isn't this working?

Discussion in 'PHP' started by cgo85, Sep 9, 2008.

  1. #1
    I can't get the links to work on this script ( echo '<a href="/city/' .$abbr. '-' .$countyurl. '-' .$cityurl. '.html" ). Something wrong with the looping but I can't figure it out. It's not getting the variables for $abbr, $cityurl, and $countyurl. Please help

    <?php
    include 'config.php';
    include 'opendb.php';
    
    $query = "SELECT cityurl, countyurl, abbr, term AS tag, COUNT(term) AS quantity
    FROM tag_cloud 
    GROUP BY term
    ORDER BY term ASC";
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_array($result)) {
        $cityurl[$row['cityurl']];
    	$countyurl[$row['countyurl']];
    	$abbr[$row['abbr']];
    	$tags[$row['tag']] = $row['quantity'];
    }
    
    // change these font sizes if you will
    $max_size = 200; // max font size in %
    $min_size = 100; // 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) {
    
        // calculate CSS 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 = $min_size + (($value - $min_qty) * $step);
        // uncomment if you want sizes in whole %:
        // $size = ceil($size);
    
        // you'll need to put the link destination in place of the #
        // (assuming your tag links to some sort of details page)
        echo '<a href="/city/' .$abbr. '-' .$countyurl. '-' .$cityurl. '.html" style="font-size: '.$size.'%"';
        // perhaps adjust this title attribute for the things that are tagged
        echo ' title="'.$value.' things tagged with '.$key.'"';
        echo '>'.$key.'</a> ';
        // notice the space at the end of the link
    }
    
    include 'closedb.php';
    
    ?>
    PHP:
     
    cgo85, Sep 9, 2008 IP
  2. matthewrobertbell

    matthewrobertbell Peon

    Messages:
    781
    Likes Received:
    35
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $cityurl[$row['cityurl']];
    $countyurl[$row['countyurl']];
    $abbr[$row['abbr']];
    $tags[$row['tag']] = $row['quantity'];

    would be useful to have an '=' on those lines so that the variables are assigned.
     
    matthewrobertbell, Sep 9, 2008 IP
  3. cgo85

    cgo85 Peon

    Messages:
    380
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This kind of works but gives same variables for every link. So, probably something along these lines:

    $cityurl = $row['cityurl'];
    	$countyurl = $row['countyurl'];
    	$abbr = $row['abbr'];
    	$tags[$row['tag']] = $row['quantity'];
    PHP:
     
    cgo85, Sep 9, 2008 IP