Jump to content

Not sure where to start...


phatgreenbuds

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.  :sweat:

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.