Forum Moderators: coopster

Message Too Old, No Replies

insert into where set

simple mysql question

         

benihana

9:17 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



im trying to classify articles into different catagories.
my plan is have a column in the articles table to hold a comma seperated list of the different catagories each article belongs to (in a numerical format - relating to the id's from the catagories table).

so far ive set up the admin pages so you can choose an article > next page to select a catagorie for that article > next page to do the insert.

im getting to the page that does the actual insertion fine - the article/cat ids sent in the url are getting there ok (im echoing them to check)

but when i try to run:

INSERT INTO articles WHERE id='$articleid' SET
types = '$classid'

i get:

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE id='8' SET types = '4''

questions:
a) whats wrong with my syntax :(?

b) im hoping to end up with a comma seperated list of all the different cats an article belongs too. is this the best way to go about it, or if i do get this working, will it write over one cat in the list when i try to add another?

thanks
ben

Timotheos

9:34 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you want to use the UPDATE [mysql.com] statement. INSERT does not allow for WHERE.

benihana

10:24 pm on Dec 8, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



thanks for your help Timotheos.

i got that working, but couldnt get it to have a full list of the different cats for each article- it woul always over write.

im going for a straight lookup table,

cheers

Matt McInvale

1:06 am on Dec 9, 2003 (gmt 0)

10+ Year Member



update TABLE set COLUMN = COLUMN ', NEWVALUE' where KEY = 'KEY';

that might work, assuming i understand what you want to accomplish.