Tags Problem!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Tags Problem!

Post by shaqa »

I have php script for audio searching,and at the end of page is implanted Tags corner,ppl when search from my search box it save the information and show at the end of my page and also "bold" most serched keywords.
Now my problem is,my table cannot handle to many keywords it change my style of my page and make it horrible for eye!
How can i fix showing example just 50 last keyword and "bold" most searched keywords using as Top Tags!?

ill publish below code that belon to "tags"

at index.php:

Code: Select all

<tr><td>
      <div id="wrapper" class="wrapper">
      Keywords:<br />
       <?php print tag_cloud(); ?>
      </div> 
      </td>
    </tr>
At header.php included in index.php

Code: Select all

 
function tag_cloud() {
 
    $min_size = 15;
    $max_size = 40;
 
    $tags = tag_info();
 
    $minimum_count = min(array_values($tags));
    $maximum_count = max(array_values($tags));
    $spread = $maximum_count - $minimum_count;
 
    if($spread == 0) {
        $spread = 1;
    }
 
    $cloud_html = '';
    $cloud_tags = array();
 
    $step = ($max_size - $min_size)/($spread);
 
 
    foreach ($tags as $tag => $count) {
        $size = $min_size + ($count - $minimum_count) 
            * $step;
 
//  $size = ($max_size + $min_size)/$spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="'. $CFG['domain'] . 'index.php?search=' . $tag . '&x=0&y=0'
            . '" title="This tag \'' . $tag  . '\' is searched ' . $count . ' times">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
}
 
at style.css

Code: Select all

.tag_cloud
    {padding: 3px; text-decoration: none;
    font-family: verdana;     }
.tag_cloud:link  {  }
.tag_cloud:hover { font-weight:bold; }
.tag_cloud:active {  }
 
div.wrapper{
    position:absolute;
    height:200px;
    width:400px;
Screenshot of my problem:
http://img30.picoodle.com/img/img30/4/1 ... 4e5d81.jpg
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

any one can help me?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Tags Problem!

Post by JAM »

Does tag_info() include a SQL clause? You could aply LIMIT 50 to that...
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

this is all of my information that i have.
how to do with that limit?
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

i want to show example: last 50 keywords or last 40 or more..
something like that.
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

i found these materials but dont what to remove and where to add the limit command.

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm
http://www.designplace.org/scripts.php?page=1&c_id=25
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Tags Problem!

Post by JAM »

What I mean is that your main function tag_cloud() contains a call to another function...

Code: Select all

$tags = tag_info();
By the looks of it, it seems that this particular function (tag_info()) contains a query to the database fetching the info about the tags being used. By editing that query, you can narrow down your search...

Code: Select all

 
    // what you MIGHT have...
    $result = mysql_query("select foo from table where something = 'moo'");
    // what you could try...
    $result = mysql_query("select foo from table where something = 'moo' LIMIT 50");
You could also try something like:

Code: Select all

    array_splice($tags, 50); // add this row before...
    foreach ($tags as $tag => $count) { // ...line 23
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

i have

Code: Select all

mysql_connect($CFG['db_host'], $CFG['db_user'], $CFG['db_pass']) or die(mysql_error());
mysql_select_db($CFG['db_name']);
 
function tag_info() { 
  $result = mysql_query("SELECT * FROM tags GROUP BY tag_name ORDER BY RAND() DESC"); 
  while($row = mysql_fetch_array($result)) { 
    $arr[$row['tag_name']] = $row['count'];
  } 
  //ksort($arr); 
  return $arr; 
}
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

working:) thank you!

so this will show my last 50 query?
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Re: Tags Problem!

Post by JAM »

If you use LIMIT 50, the query will only limit the amount of hits to just that number, 50.

If you want the last searches, you also need to edit the ORDER BY RAND() DESC part, as this shuffles the order. Remove the order by clause, or rewrite it to fit your needs, and use limit 50. Then you could apply some shuffling to the resulting array instead, making the searchcloud look like a cloud.

Hhope I made sence... Busy at work.
shaqa
Forum Commoner
Posts: 62
Joined: Mon Aug 13, 2007 9:11 am

Re: Tags Problem!

Post by shaqa »

To much thanks!
one last thing. how do i integrate Word filter.
i have found some tutorial about that but dont know how to join in my script,
i dont want to make any replacement, just want to disable showing "bad words"

Code: Select all

$string=$_POST['string'];
$query="SELECT `word`,`replace` FROM `words`";
$result = mysql_query($query);
 
$bad_words = Array(); //bad words list
$rep_words = Array(); //replace words list
 
while($row=mysql_fetch_assoc($result)) { //get associative index only
    $bad_words []= $row['word'];
    $rep_words []= $row['replace'];
}
$string = str_replace($bad_words,$rep_words,$string);
or

Code: Select all

$querys ="SELECT * FROM filter";  
 
 
    $query_resultmessage = mysql_query ($query, $db_connection);  
$words = ''; 
 
while ($row = mysql_fetch_object($query_resultmessage)) {  
  $words .= $row->filterword.'|';  
}  
 
    //Start word filter  
  $bad_words = explode('|', $words); 
 
   foreach ($bad_words as $naughty)  
   {  
      $wmessage = str_replace($naughty, '&nbsp;', $wmessage);  
   } 
 
print "<td>$wmessage</td>";
or

Code: Select all

mysql_query (SELECT * FROM bad words list..... 
 
$badwords=MYSQL_FETCH_ARRAY(YOUR RESULT); 
OR 
 
$badwords=array("word1","word2"); 
 
for($x=0; $x< count($badwords); $x++) 
{ 
$input = eregi_replace($badwords[$x], "****", $input); 
 
} 
 
Replaces bad words with **** in $input
Post Reply