Jump to content

Archived

This topic is now archived and is closed to further replies.

spires

A point in the right direction

Recommended Posts

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 See
http://www.theeventorganiser.com/reg_more_cats.php

But 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.g
ROW 1
id=1
cat=Decor
sub= Inflatables

ROW 2
id=1
cat=DJs
sub= House
etc

Any help please, Just need an idea of how this coul be done thanks.

Share this post


Link to post
Share on other sites
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]<?php
foreach ($_POST['sub'] as $subcat) {

    mysql_query ("INSERT INTO mytablename (username, subcat)
                  VALUES ('$userid', '$subcat') ");
}
?>[/code]

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.