I have a php mysql tag cloud setup for my website. The issue is that it's storing stuff in database that have no values. How can I stop it from doing this. I need a command that will tell it to only store the info if there is a value for field 'term'... here is a snippet of the code. $parse = parse_url($_SERVER['HTTP_REFERER']); $se = $parse["host"]; $raw_var = explode("&", $parse["query"] ); foreach ($raw_var as $one_var) { $raw = explode("=", $one_var); $var[$raw[0]] = urldecode ($raw[1]); } $se = explode (".", $se); switch ($se[1]) { case 'yahoo': $keywords = $var['p']; break; case 'aol': $keywords = $var['query']; break; default: $keywords = $var['q']; } unset($parse, $se, $raw_var, $one_var, $var); mysql_query ("INSERT INTO tag_cloud (term, countyurl, cityurl, abbr) VALUES ('$keywords', '$countyurl', '$cityurl', '$abbr')"); PHP:
if ($keywords <> '') { mysql_query ("INSERT INTO tag_cloud (term, countyurl, cityurl, abbr) VALUES ('$keywords', '$countyurl', '$cityurl', '$abbr')"); } PHP:
^above or you could do if(strlen($keyword) > 3) { ...insert into database } that way single letters won't show up as tags.
Many web developer use this, instead of <>'' Anyway both will give same result. if (!empty($keyword)) { mysql_query ("INSERT INTO tag_cloud (term, countyurl, cityurl, abbr) VALUES ('$keywords', '$countyurl', '$cityurl', '$abbr')"); } PHP: Or you can use more advantage option with set of minimum string lenght, that have been posted by clinton
you can also use if (trim($keywords) <> '') { mysql_query ("INSERT INTO tag_cloud (term, countyurl, cityurl, abbr) VALUES ('$keywords', '$countyurl', '$cityurl', '$abbr')"); } trim function removes the space at the both ends.