Submit Your Article Forum Rules

Results 1 to 2 of 2

Thread: Why I can't split the comma?

  1. #1
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    Question Why I can't split the comma?

    Hi

    I am trying to create a Tag Cloud from my database. Under my database for Tags, the words are separated by commas, so I am trying to split it as individual word by eliminating the commas but it does not seem to work. Any idea what is wrong with my code?

    Code:
    <?php
    
    $query = "SELECT Tags AS Tag, COUNT(ID) AS quantity 
      FROM post_video
      GROUP BY Tags
      ORDER BY Tags DESC LIMIT 50";
    
    $result = mysql_query($query);
    
    
    while ($row = mysql_fetch_array($result)) {
    
        $temp_Tags = explode(',', $row['Tags']);
    
        foreach ($temp_Tags as $Tags) {
            if (isset($Tags[$Tag])) {
                $Tags[$Tag]++;
            } else {
                $Tags[$Tag] = 1;
            }
        }
    
    
        $Tags[$row['Tag']] = $row['quantity'];
    $category_id[$row['Tag']] = $row['category_id'];
    
    }
    
    $max_size = 250; // max font size in %
    $min_size = 100; // min font size in %
    
    
    $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;
    }
    
    
    $step = ($max_size - $min_size)/($spread);
    
    // loop through our tag array
    foreach ($Tags as $key => $value) {
    
        $size = $min_size + (($value - $min_qty) * $step);
    
        echo '<a href="index.php?cat_id='.$category_id[$key].'"
          style="font-size: '.$size.'%"
          title="'.$value.' things tagged with '.$key.'">'
          .$key.'</a> ';
    
    }
    
    ?>
    Any help is greatly appreciated.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

  2. #2
    WebProWorld MVP edhan's Avatar
    Join Date
    Aug 2003
    Posts
    941

    Re: Why I can't split the comma?

    This is solved.

    For benefit of others, the solution is:

    Instead of $temp_Tags = explode(',', $row['Tags']);

    It should be $temp_Tags = explode(', ', $row['Tags']);

    I forget to add a space after the comma.
    Find Out More About Renting Thai Amulets For Blessing Of Protection in Well Being & Wealth | Destiny of Fate | Exploring, Understanding & Learning The Basic Feng Shui Art Of Placement To Build Wealth & Harmony With Friends, Colleagues And Family Members In Relationships & Careers... Do you want a better lifestyle? Check it out today!

Similar Threads

  1. Comma or not to comma, that is the question!
    By Conficio in forum Search Engine Optimization Forum
    Replies: 8
    Last Post: 05-19-2008, 05:55 PM
  2. Comma in Keyword Meta tag
    By habib in forum Google Discussion Forum
    Replies: 3
    Last Post: 02-29-2008, 08:02 AM
  3. Comma in Keyword Meta?
    By Texlend in forum Yahoo! Discussion Forum
    Replies: 5
    Last Post: 12-05-2007, 04:00 PM
  4. To Comma or not to Comma, that is the question
    By webwoman in forum Search Engine Optimization Forum
    Replies: 2
    Last Post: 10-20-2004, 11:27 AM
  5. Keywords: comma or spaces
    By jaca in forum Search Engine Optimization Forum
    Replies: 25
    Last Post: 02-09-2004, 11:37 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •