#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0

    Talking Function Most repeated words


    Hello ,

    I am looking for a " function Most 10 repeated words " from field [ page_keywords ] in database table [ pages ] ...

    the words in field like that
    page,google,facebook,smile,more,post,thread,msn,elc.

    i want count all words and select only Most 10 repeated words and explode "," and without number and any another signs like [@,#,$,%,^,&,*,elc]

    to get in the end Most 10 repeated words like this

    google facebook page page


    thnx ,

  2. #2
  3. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Originally Posted by omardealo
    the words in field like that
    page,google,facebook,smile,more,post,thread,msn,elc.
    Well that sucks. Can you change your database structure at all?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Well that sucks. Can you change your database structure at all?
    change for what and why ?
    on any database ,the tags words in field like same ..
    page,google,facebook,smile,more,post,thread,msn,elc.
  6. #4
  7. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Change for why: it's bad data structure and is hard to use. As you're finding out.
    Change for what: rather than store everything as a comma-separated list, store everything in a table with one row per page per keyword.
    Code:
    page id | keyword
    --------+--------
          1 | page
          1 | google
          1 | facebook
          1 | smile
          1 | more
          1 | post
          1 | thread
          1 | msn
    So the question stands: can you change the database structure?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Change for why: it's bad data structure and is hard to use. As you're finding out.
    Change for what: rather than store everything as a comma-separated list, store everything in a table with one row per page per keyword.
    So the question stands: can you change the database structure?
    okay , requinix
    maybe u are right ... but i can't change for that actually
    listen i use that Function for same database and same field


    PHP Code:
    function get_keys($text,$limit=10){
                
    $separaotr " ";   // the separator between the words
                
    $text str_replace(array('&','^',',',';','<','>','_','$','%','#','@','+','=','-','/','*',')','(','0',']','[','{','}'),$separaotr,$text) ;
                
    $text trim(strtolower($text));
                
    $text implode($separaotrarray_slice(explode($separaotr ,$text), 0$limit));
                
    $tags array_unique(explode($separaotr,$text));
                
    $num count($tags) ;   //  number of tags you want
                
    for ($z=0;$z<=$num;$z++){
                 
    $words .= '<a title="'.$tags[$z].'" href="search.php?q='.$tags[$z].'">'.$tags[$z].'</a> ';
                 if(
    $z $num-1){
                   
    $words .= '  ';
                 }
                }
                return 
    $words;

    this function show The words without repetition and without Signs , worked fine
    but i want only Most 10 repeated words
    can u Modify for what I want ...

    the query :

    PHP Code:
    $tags = @mysql_query("SELECT page_keywords FROM pages ") or die(mysql_error()); 
    used function :

    PHP Code:
    echo get_keys($keywords,50); 

    thnx , requinix
  10. #6
  11. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Sep 2006
    Posts
    2,037
    Rep Power
    535
    Why can't the database schema be changed as requinix suggested? Is some else responsible for the database? If so, they should be fired.
  12. #7
  13. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    If you really can't do anything about it then the solution is (looks like) what you have: get all the keywords from all the pages and tally them in PHP.
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    If you really can't do anything about it then the solution is (looks like) what you have: get all the keywords from all the pages and tally them in PHP.
    i do that already , i get all keywords from all pages
    by this
    PHP Code:
    $tags = @mysql_query("SELECT page_keywords FROM pages ") or die(mysql_error()); 
    and Query results come like that
    PHP Code:
    page,google,facebook,smile,more,post,thread,msn,elc
    so , where's the function Which will be it job
    Get only Most 10 repeated words without number and any another signs
    Last edited by requinix; December 2nd, 2012 at 11:52 PM.
  16. #9
  17. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Don't yell. You won't win.

    The function will be the one you write. Because we're not going to write it for you.
    You already have a list of the keywords. If you need something to count the keywords then
    PHP Code:
    $count = array();
    // for each $keyword in the list {
        
    if (isset($count[$keyword])) $count[$keyword] = 0;
        
    $count[$keyword]++;
    // } 
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    Don't yell. You won't win.

    The function will be the one you write. Because we're not going to write it for you.
    You already have a list of the keywords. If you need something to count the keywords then
    PHP Code:
    $count = array();
    // for each $keyword in the list {
        
    if (isset($count[$keyword])) $count[$keyword] = 0;
        
    $count[$keyword]++;
    // } 
    okay .. i understand
    I did not ask you to write new function
    I thought that there already function Available for this job
    and i don't yell , sorry but u want me modification the database and i don't want do this ...
    thnx ... requinix


    Administration can be closed subject
  20. #11
  21. Transforming Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,245
    Rep Power
    9400
    Originally Posted by omardealo
    okay .. i understand
    I did not ask you to write new function
    I thought that there already function Available for this job
    That counts keywords in your database? Not really. That's a very specific question.

    Comments on this post

    • omardealo agrees : thnx
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    That counts keywords in your database? Not really. That's a very specific question.
    i don't understand ur comment
    anyway i will search more about i want
    thnx for u !
  24. #13
  25. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    3
    Rep Power
    0

    Function Most repeated words


    I am looking for a functions that would get me the most repeated word in a sentence and order desc by number of times.

    Comments on this post

    • ptr2void disagrees : Useless spammer

IMN logo majestic logo threadwatch logo seochat tools logo