Basic Loop, SQL Question

Lets say I have two tables. In table “category_name”, there are fields category.id and category.name. In table “category_subscriptions” there are fields userid and category.number.

What I want to be able to do is to insert a row into category_subscriptions for each category.id using the same userid.

Consider “category_name” having the following values: 4, cars, 5, trucks, 6, trains

The ideal output table for “category_subscriptions (for userid=99) would have values: 99,4,99,5,99,6

Rather than use:

INSERT INTO category_subscriptions
VALUES (99,4)

INSERT INTO category_subscriptions
VALUES (99,5)

INSERT INTO category_subscriptions
VALUES (99,6)

I think I should be using a loop, as category.id won’t always be 4,5, &6. I’m just not sure if this is right and am hoping somebody can help. This is part of a plugin for Joomla 1.7/php.

Sponsor our Newsletter | Privacy Policy | Terms of Service