Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-21-2007, 10:58 AM
edhan's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Singapore
Posts: 581
edhan RepRank 1
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.
Reply With Quote
  #2 (permalink)  
Old 12-15-2007, 08:44 AM
edhan's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Singapore
Posts: 581
edhan RepRank 1
Default 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.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags:



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
To split or not to split! Please help alextj Search Engine Optimization Forum 4 07-13-2006 07:20 AM
Keyword Meta tag: White space or comma separation? prasadr Search Engine Optimization Forum 2 05-30-2005 09:28 PM
To Comma or not to Comma, that is the question webwoman Search Engine Optimization Forum 2 10-20-2004 12:27 PM
Keywords: comma or spaces jaca Search Engine Optimization Forum 25 02-09-2004 12:37 PM


Search Engine Optimization by vBSEO 3.2.0