php - How to make multiple tags system for blogs? -


i have database setup this:

posts     post_id; primary_key     title;     content;     date; tags     tag_id; primary_key     post_id;     tag_name; 

in blog, i'm letting users post own tags, youtube. lets say, i'm letting users type tags in input box. example, user types: cat dog food.

i want php convert input array , store in data base this.

tags      tag_id | post_id | tag_name         1       1       cat         2       1       dog         3       1       food 

i think can convert string array using explode(). however, how structure query store database way want?

i want php break each tag down, , store each tag in separate row.

i'm using while loop pull each tags post btw.

use foreach loop. ie

$string= "cat,lion"; $array= explode(",",$string); foreach($array $tag) {   mysql_query("insert tags(tag_id,post_id,tag_name) values('','$post_id','$tag')"); // run query insert tags table. $post_id corresponding post_id have. } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -