SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    May 2008
    Posts
    231
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to store search "keywords" in a table and use for Tag cloud

    I want to a Tag cloud that is based on the frequency of search "keywords" that users use in searching a product table in my database.
    My search script looks for keyword in Product_description field and product_name field.
    PHP Code:
    //specify how many results to display per page
    $limit 10;

    // Get the search variable from URL
    $var = @$_POST['q'] ;

    //trim whitespace from the stored variable
    $trimmed trim($var);

    //separate key-phrases into keywords
    $trimmed_array explode(" ",$trimmed);
    // Build SQL Query for each keyword entered
    foreach ($trimmed_array as $trimm){
          
    // EDIT HERE and specify your table and field names for the SQL query
         
    $query "SELECT * FROM product WHERE product_description LIKE '%$trimm%' OR product_name like '%$trimm%' OR product_category like '%$trimm%' ORDER BY product_description  DESC" ;
         
    // Execute the query to  get number of rows that contain search kewords
         
    $numresults=mysql_query($query);
         
    $row_num_links_main =mysql_num_rows($numresults); 

    Am just confuse on how to store keywords from search and retrieve for tag cloud.
    can someone help because it's confusing to me

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Well you will need to create a table of keywords and store them. When you have enough you can then extract them using DISTINCT and constrain them by date to make a tag cloud.

    You could insert another query into that loop.
    PHP Code:
    "insert into 
    keywords (keyword) 
    values ('" 
    mysql_real_escape_string$trimm ) . "');
    "

    Make sure the table has a datetime field and it should update with time the record was created, so you have a word and a time/date.

    Note the escaping of text before sending it to your database to halt sql injection attacks.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •