Forum Moderators: coopster

Message Too Old, No Replies

MySQL uploading a number of inserts in one statement

MySQL uploading a number of inserts in one statement

         

npulis

9:29 am on Jan 9, 2010 (gmt 0)



Hi,

I have to create the tags related to a post in the table 'post_tags'.

Example I have post with ID 1 and I need to assign tag 5, 6 and 7 to the post but putting the entries in the 'post_tags' table.

postid/ posttag
1 5
1 6
1 7

Is there a way to put them all in one statement rather than having to make an SQL statement for each one?

At the moment it's
INSERT INTO posttags (postid, tagid) values (1, 5)
INSERT INTO posttags (postid, tagid) values (1, 6)
INSERT INTO posttags (postid, tagid) values (1, 7)

I am looking maybe there is a better way how to do it.

Thanks :)

Psychopsia

2:22 pm on Jan 9, 2010 (gmt 0)

10+ Year Member



Hi npulis!

You can store tags in one field, separated by spaces or another character.

If you need some kind of comparison, then extract it from db, and do an 'explode' to get all values in an array.

npulis

2:27 pm on Jan 9, 2010 (gmt 0)



Thanks dude :) didn't know it was so easy, lol :(