how to save tags(keywords) in database?

后端 未结 3 2212
隐瞒了意图╮
隐瞒了意图╮ 2021-02-13 19:50

I want to create a simple tags system using php and mysql, so that users can add few tags via form. My question is that should i save the tags as an array in single database col

3条回答
  •  旧时难觅i
    2021-02-13 20:39

    You could use serialise and unserialise to store the keywords in one field. More info here http://php.net/manual/en/function.serialize.php

    Something like this...

    $keywords = array('apple', 'pear', 'banana', 'peach');
    $keywords_serialized = serialize($keywords);
    $sql = INSERT INTO dbtable (keywords) VALUES ($keywords_serialized);
    

提交回复
热议问题