1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

help woth cloud tag

Discussion in 'PHP' started by member1, May 12, 2007.

  1. #1
    hello !
    can any one help me with this script

    i want make tag cloud in my home page so i take this script from
    http://www.scriptplayground.com/tutorials/php/Tag-Cloud/

    fierst i amke a new databse and anclud this

    and copy all this script to empty php page just a change the information about data base

    <?php
    function get_tag_data() { 
      mysql_connect('xxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxx');
      mysql_select_db('xxxxxxxxxxx');
      $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC"); 
      while($row = mysql_fetch_array($result)) { 
        $arr[$row['tag']] = $row['count'];
      } 
      ksort($arr); 
      return $arr; 
    }
    ?>
    <style type="text/css">
    .tag_cloud { padding: 3px; text-decoration: none; }
    .tag_cloud:link  { color: #81d601; }
    .tag_cloud:visited { color: #019c05; }
    .tag_cloud:hover { color: #ffffff; background: #69da03; }
    .tag_cloud:active { color: #ffffff; background: #ACFC65; }
    </style>
    
    <?php
    function get_tag_cloud(). { ... };
    
    // Default font sizes
    $min_font_size = 12;
    $max_font_size = 30;
    
    // Pull in tag data
    $tags = get_tag_data();
    
    $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(); // create an array to hold tag code
    foreach ($tags as $tag => 
    <p>$count) {
    	$size = $min_font_size + ($count - $minimum_count) 
    		* ($max_font_size - $min_font_size) / $spread;
    	$cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
    		. '" class="tag_cloud" href="http://www.google.com/search?q=' . $tag 
    		. '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
    		. htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;</p>
    ?>
    
    <body><h3>Sample Tag Cloud results</h3>
    <div id="wrapper"
    <!-- BEGIN Tag Cloud -->
    <?php print get_tag_cloud(); ?>
    <!-- END Tag Cloud -->
    </div>
    
    PHP:

    but there is nothig he show me this error

    Parse error: parse error, unexpected '.', expecting '{' in /homepages/3/d192671145/htdocs/DDL/tag.php on line 22
    PHP:
    can any one help me with that please

    i test it like in the same page if he work i said i will move that script to my home page

    <body><h3>Sample Tag Cloud results</h3>
    <div id="wrapper"
    <!-- BEGIN Tag Cloud -->
    <?php print get_tag_cloud(); ?>
    <!-- END Tag Cloud -->
    </div>
    PHP:
    can any one help me with that
     
    member1, May 12, 2007 IP
  2. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #2
    It's poorly explained on this website, but where the function is marked, it's just supposed to start there. It should be closed later though.

    Try this. (Untested)

    
    <?php
    function get_tag_data() { 
      mysql_connect('xxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxx');
      mysql_select_db('xxxxxxxxxxx');
      $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC"); 
      while($row = mysql_fetch_array($result)) { 
        $arr[$row['tag']] = $row['count'];
      } 
      ksort($arr); 
      return $arr; 
    }
    ?>
    <style type="text/css">
    .tag_cloud { padding: 3px; text-decoration: none; }
    .tag_cloud:link  { color: #81d601; }
    .tag_cloud:visited { color: #019c05; }
    .tag_cloud:hover { color: #ffffff; background: #69da03; }
    .tag_cloud:active { color: #ffffff; background: #ACFC65; }
    </style>
    
    <?php
    function get_tag_cloud() 
    {
    
    // Default font sizes
    $min_font_size = 12;
    $max_font_size = 30;
    
    // Pull in tag data
    $tags = get_tag_data();
    
    $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(); // create an array to hold tag code
    foreach ($tags as $tag => $count) {
        $size = $min_font_size + ($count - $minimum_count) 
            * ($max_font_size - $min_font_size) / $spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="http://www.google.com/search?q=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
    }
    ?>
    
    <body><h3>Sample Tag Cloud results</h3>
    <div id="wrapper"
    <!-- BEGIN Tag Cloud -->
    <?php print get_tag_cloud(); ?>
    <!-- END Tag Cloud -->
    </div>
    
    PHP:
     
    nico_swd, May 12, 2007 IP
    Subikar likes this.
  3. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #3
    thanks you for replay me tanks your script is work

    but hi show just
    that
    Sample Tag Cloud results

    whay the tag dont showup
     
    member1, May 12, 2007 IP
  4. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #4
    I'm not sure if I understand you right, but did you add rows with tags to the database?
     
    nico_swd, May 12, 2007 IP
  5. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #5
    what i did is just what i right here

    this is the sql table is like this

    CREATE TABLE tags (
    id int(11) NOT NULL,
    tag varchar(100) NOT NULL,
    count int(11) NOT NULL DEFAULT '0'
    );
    PHP:
    and the page tag.php

    i just put this

    <?php
    function get_tag_data() { 
      mysql_connect('xxxxxxxxx', 'xxxxxxxxxx', 'xxxxxxxxx');
      mysql_select_db('xxxxxxxxxxx');
      $result = mysql_query("SELECT * FROM tags GROUP BY tag ORDER BY count DESC"); 
      while($row = mysql_fetch_array($result)) { 
        $arr[$row['tag']] = $row['count'];
      } 
      ksort($arr); 
      return $arr; 
    }
    ?>
    <style type="text/css">
    .tag_cloud { padding: 3px; text-decoration: none; }
    .tag_cloud:link  { color: #81d601; }
    .tag_cloud:visited { color: #019c05; }
    .tag_cloud:hover { color: #ffffff; background: #69da03; }
    .tag_cloud:active { color: #ffffff; background: #ACFC65; }
    </style>
    
    <?php
    function get_tag_cloud() 
    {
    
    // Default font sizes
    $min_font_size = 12;
    $max_font_size = 30;
    
    // Pull in tag data
    $tags = get_tag_data();
    
    $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(); // create an array to hold tag code
    foreach ($tags as $tag => $count) {
        $size = $min_font_size + ($count - $minimum_count) 
            * ($max_font_size - $min_font_size) / $spread;
        $cloud_tags[] = '<a style="font-size: '. floor($size) . 'px' 
            . '" class="tag_cloud" href="http://www.google.com/search?q=' . $tag 
            . '" title="\'' . $tag  . '\' returned a count of ' . $count . '">' 
            . htmlspecialchars(stripslashes($tag)) . '</a>';
    }
    $cloud_html = join("\n", $cloud_tags) . "\n";
    return $cloud_html;
    }
    ?>
    
    <body><h3>Sample Tag Cloud results</h3>
    <div id="wrapper"
    <!-- BEGIN Tag Cloud -->
    <?php print get_tag_cloud(); ?>
    <!-- END Tag Cloud -->
    </div>
    PHP:
    thats it

    this is all i did
     
    member1, May 12, 2007 IP
  6. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #6
    Okay, and now you're wondering why no tags appear? You have to add them manually to the database. This script doesn't invent tags.

    This script is meant to have a purpose. It's not meant to display random words on your website to make it look web 2.0'ish. Do you have a blog or something that could use tags in a meaningful way?

    Usually tags relate to an article, post, or just a page on your website. You have to know what you want to do before you start using random scripts.
     
    nico_swd, May 12, 2007 IP
  7. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #7
    i have a web site in php
    what i want before is to make for exemple whene visitor he search in the site that word he appear like recent search and i dont know verymuch in php so i foundout this tag i hope to make it like that most recent search apear in tag
     
    member1, May 12, 2007 IP
  8. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #8
    Would the user search via an existing search engine in your site, or via Google/Yahoo/MSN, etc...?
     
    nico_swd, May 13, 2007 IP
  9. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #9
    no i have search engine in my site and the recent search whene he search from my search engine not from google
     
    member1, May 13, 2007 IP
  10. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #10
    I will need your code then, if you want me to help you to insert the search keywords into your tags table.
     
    nico_swd, May 13, 2007 IP
  11. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #11
    do you mean tat code of search engine or the code of all the main page

     
    member1, May 13, 2007 IP
  12. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #12
    Place this in "search.php":

    
    if (isset($_POST['q']))
    {
    	$keywords = preg_split('/[\s,]+/', $_POST['q'], -1, PREG_SPLIT_NO_EMPTY);
    	
    	foreach (array_unique($keywords) AS $keyword)
    	{
    		$keyword = mysql_real_escape_string(trim($keyword));
    		
    		if (strlen($keyword) < 2)
    		{
    			continue;
    		}
    	
    		mysql_query("UPDATE tags SET count = (count + 1) WHERE tag = '". $keyword ."' LIMIT 1") OR die(mysql_error());
    		
    		if (!mysql_affected_rows())
    		{
    			mysql_query("INSERT INTO tags (tag, count) VALUES ('". $keyword ."', 1)") OR die(mysql_error());
    		}		
    	}
    }
    
    PHP:
    Untested...
     
    nico_swd, May 13, 2007 IP
  13. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #13
    he give this

    related to them.
    Table 'xxxxxxx.tags' doesn't exist

    becose the tag table i creat in other database i have to creat another in database of the site
     
    member1, May 13, 2007 IP
  14. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #14
    Or you can change the database by using:
    
    mysql_select_db('db_name') OR die(mysql_error());
    
    PHP:
    If that doesn't work, try creating the table in the database you're actually using.
     
    nico_swd, May 13, 2007 IP
  15. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #15
    he dont work dont show anything
    i move out the data base to the site and whene i search he dont show nothing

    what exacler i did

    becouse the recent search is in the footer of the page so the
    script you give me i just add in fierst <?php and last ?> and past it in the footer of the page

    i tray to search something but there is nothing inrecent search
     
    member1, May 13, 2007 IP
  16. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #16
    any edia about this please

    help please
     
    member1, May 13, 2007 IP
  17. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #17
    Can you post the PHP code of "search.php"?
     
    nico_swd, May 14, 2007 IP
  18. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #18
    LIKE I SAID HE DONT SHOWS THE RESULTA WITH THAT CODE

    THE CODE WITH database he work fine but this he dont show nothing

     
    member1, May 14, 2007 IP
  19. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #19
    nico_swd, May 14, 2007 IP
  20. member1

    member1 Active Member

    Messages:
    65
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    68
    #20
    i did it i use it this code and delete this from the code becose you give me another in the head


    but he show me this error

     
    member1, May 14, 2007 IP