tag cloud out of database

Discussion in 'PHP' started by igorov, Sep 11, 2010.

  1. #1
    Hello;
    I have got a dictionary website. It consists of three pages: index and two result pages. Naturally, I believe, it is not indexed by search engines. I think I need a tag cloud but I don't know how to make it. I have made a search and there were results and examples showing how to make tag clouds. However, I could find none that could make it out of a database. All the words and definitions are in a database.
     
    igorov, Sep 11, 2010 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    Tag Cloud scripts are just based on hits to an item, well that would be the simplest form. So basically all your doing is selecting items with the highest hit count and displaying those in a fancy format. Which means you need a hit field added to your database words table.

    If you post up some code you found, I am sure someone or even myself will alter it so it reads from a db instead.
     
    MyVodaFone, Sep 11, 2010 IP
  3. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Here is a code that I found. It simply makes a list of the words but it is only a list. Moreover, nothing happens when you click on them. Note that my purpose is to get recognized by search engines. Therefore, the tag cloud can remain in a seperate file, if possible. Thanks in advance.
    $query = "SELECT word AS tag, COUNT(id) AS quantity
    FROM mydatabase
    GROUP BY word
    ORDER BY word ASC";
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_array($result)) {
    $tags[$row['tag']] = $row['quantity'];
    }
    
    
    $max_size = 250;
    $min_size = 100;
    
    $max_qty = max(array_values($tags));
    $min_qty = min(array_values($tags));
    
    $spread = $max_qty - $min_qty;
    if (0 == $spread) {
    $spread = 1;
    }
    
    $step = ($max_size - $min_size)/($spread);
    
    foreach ($tags as $key => $value) {
    
    $size = $min_size + (($value - $min_qty) * $step);
    
    
    echo '<a href="kelime1.php" style="font-size: '.$size.'%"';
    
    
    echo ' title="'.$value.' thing tagged with '.$key.'"';
    echo '>'.$key.'</a> ';
    
    }
    Code (markup):
     
    igorov, Sep 11, 2010 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Just an opinion, but a site map might suite you better. Which is really all that script above does, ie: it creates links, by words
     
    MyVodaFone, Sep 11, 2010 IP
  5. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    A sitemap of 3 pages? I don't think that would help as the real content is in the database. Moreover, the links it creates doesn't work
     
    Last edited: Sep 11, 2010
    igorov, Sep 11, 2010 IP
  6. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #6
    Sounds like you need to use rewrite rules. Can you show us your site please.
     
    MyVodaFone, Sep 11, 2010 IP
  7. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    site sent in pm
     
    igorov, Sep 11, 2010 IP
  8. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #8
    You need to change your php script so the "words" can be captured and then processed into working urls like ursite.com/word then you can use the script above.

    I can help you with that, if you want to post the script here in or a PM etc...
     
    MyVodaFone, Sep 11, 2010 IP
  9. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    I want the search result to appear in the browser address bar like this: .../result.php?s=word
    The "word" will be replaced with the actual word being looked up. In this way, I believe, I will be able to provide links for the results, which I can use with the tags.
     
    igorov, Sep 12, 2010 IP
  10. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #10
    That's what I meant, to get your started, use the word GET on your forum instead of POST that will give you ?s=word, however on your forum your not using the letter s so you need to change that as well... and to continue on, if you add a little htaccess trick you can turn ?s=word in to /word or /word.htm
     
    MyVodaFone, Sep 13, 2010 IP
  11. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Thank you very much MyVodafone; it works! I didn't know that it would be so simple. However, what appears is not exactly what I wanted. This is what I get when I look up the word "able", for example:
    .../kelime1.php?kelime=able&Submit=+++++Bak+++++++
    Why do I have the "&Submit=+++++Bak+++++++" extension after that word? "Bak" is the name of the submit bottton.
    By the way, what kind of change shall I apply to the htaccess?
     
    igorov, Sep 13, 2010 IP
  12. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #12
    Its to do with your form, remove the name=Bak tag you added to your submit button, you don't need it
     
    MyVodaFone, Sep 13, 2010 IP
  13. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Well, I can get the link to a word by typing .../kelime1.php?kelime=able and that is what I needed. Thank you very much. By the way how does the magic with the htaccess work? What shall I exactly do?
     
    igorov, Sep 13, 2010 IP
  14. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #14
    Just to clarify, these methods are the basics and there are other ways, preferable ways etc... but to get you going heres a quick way.

    You do need to remove the name=bak from your submit button, the url must be /kelime1.php?kelime=word for it to work.

    Create a .htaccess file and place the following in to it.
    
    Options +FollowSymLinks
    
    RewriteEngine on
    
    RewriteBase /
    
    RewriteRule ^([^/]+)\.htm?$ kelime1.php?kelime=$1 [L]
    
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /kelime1\.php\?kelime=([^&]+)\ HTTP/
    
    RewriteRule ^kelime1\.php$ /%1\.htm? [R=301,L]
    
    PHP:
    You can remove the .htm if you wish, its optional.
     
    MyVodaFone, Sep 13, 2010 IP
  15. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #15
    Thank you very much indeed. I don't know how to thank you. Should I click the + at the right bottom corner? Is this +rep that you mention in the signature? I can also give you a featured link on my directory website. I am not sure that would be enough help because I have been searching the internet several days to find an answer.
     
    igorov, Sep 13, 2010 IP
  16. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #16
    Your fine, this is a free forum...
     
    MyVodaFone, Sep 13, 2010 IP
  17. igorov

    igorov Guest

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #17
    Thank you again. You have been of great help. It worked like miracle :)
     
    igorov, Sep 13, 2010 IP