phatgreenbuds Posted November 25, 2009 Share Posted November 25, 2009 So the plan is to create a page where people who have uploaded their pic can then create key words to search for them later. For instance if I upload the family photos from thanksgiving I want to be able to include the terms "Turkey, Gravy, Cranberry, etc etc." I assume I have to do this with an array and thats where I start losing my mind. What method should I use to store that array in the DB? Serialize? Implode? There are so many different opinions on google's random page results, I thought best to come here where I have always had success. Step one is to present the options. I plan to use static options in the form of check boxes for now (text fields later). Step two is to store that array in the DB...The reason I am here now. Step three will be to create a means to search that DB for arrays that contain those key words...I am sure I will be back for that. As always I am not looking for the "code handout" but rather the pointer or hints that would help me figure it out myself. Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/ Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 If you're going to be searching Keywords, it will be easier to implode that array, and store it in a TEXT-field. Also make sure that text-field is a FULLTEXT key. Serializing an array would be more work as you have unserialize the retrieved arrays and then compare them to the searched keywords. Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/#findComment-965253 Share on other sites More sharing options...
phatgreenbuds Posted November 25, 2009 Author Share Posted November 25, 2009 What do you mean here? Also make sure that text-field is a FULLTEXT key I assume you mean no strange characters to be used as a seperator in the implode function...or am I missing it? Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/#findComment-965258 Share on other sites More sharing options...
Goldeneye Posted November 25, 2009 Share Posted November 25, 2009 Well, if you're using MySQL and phpMyAdmin, you create a field with a name of your choice (maybe `keywords`), select "TEXT" under fieldtype, and check the FULLTEXT checkbox. Just implode the keywords with spaces: $keywords = array('foo', 'bar', 'twix', 'none', 'for', 'you'); $keywords = implode(' ', $keywords); //And then insert $keywords into your Database Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/#findComment-965259 Share on other sites More sharing options...
phatgreenbuds Posted November 25, 2009 Author Share Posted November 25, 2009 ahhh gotcha...ok kool this is getting my brain going again...once I finish this part I will begin the searching portion. but for now its the tedious presentation work. Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/#findComment-965261 Share on other sites More sharing options...
keldorn Posted November 25, 2009 Share Posted November 25, 2009 What I would do, is tell them to seperate each word a , Then on a post i would take it and check for against a whitelist of characters with a regex to allow only letters and numbers and colons (,) Then I would explode it into a an array value via each colon, then iterate threw each value and apply trim() , utf8_encode() and strtolower(), then ucfirst(), Then strlen() each value to make sure its not longer then set about of characters, and is also longer then 3 characters, else reject it. Then I would iterate over each value again with mysql_real_escape_string() Then next I would place it into a database , each word, would get its own row, but I would set the colume the word is in, as Unique index, so if it return false, after the query, then I would run the mysql_query again on that row, and increment a counter in the table by +1. To generate the tags, I would grab say, 20 row, ORDER BY counter ASC and apply a mathematical formula against all 20 words, and make the words bigger that have a higher value in their counter. EDIT: I probably need to sleep, I thought you wanted a tag cloud. Quote Link to comment https://forums.phpfreaks.com/topic/182872-not-sure-where-to-start/#findComment-965296 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.