spires Posted August 30, 2006 Share Posted August 30, 2006 Hi, Can anyone tell me how to INSERT mulitpul rows into a table at the same time?I have a table with categories and sub categories, I would like for the user to be able to select ass many options as they want. So i have echoed out all of the cat and sub cat with checkbox next to them. Please Seehttp://www.theeventorganiser.com/reg_more_cats.phpBut i dont know how to set up the query so it will upload each cat and sub cat on a row of its own?e.gROW 1id=1cat=Decorsub= InflatablesROW 2id=1cat=DJssub= HouseetcAny help please, Just need an idea of how this coul be done thanks. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 30, 2006 Share Posted August 30, 2006 So you have a table like this. I assume the id's are different despite your example?[pre]| id | cat | subcat ||----|---------|-----------------|| 1 | Decor | Inflatables || 2 | Decor | Interior design || 3 | DJs | Funky || 4 | DJs | House || 5 | Laser | Engineer |[/pre]Name your checkboxes like this, giving each the id of the subcat as its value [code]echo "<input type='checkbox' name='sub[]' value='$id'>";[/code]As only check checkboxes are posted you can then save the users' requirements with[code]<?phpforeach ($_POST['sub'] as $subcat) { mysql_query ("INSERT INTO mytablename (username, subcat) VALUES ('$userid', '$subcat') ");}?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.