Jump to content


Photo

A point in the right direction


  • Please log in to reply
1 reply to this topic

#1 spires

spires
  • Members
  • PipPipPip
  • Advanced Member
  • 492 posts

Posted 30 August 2006 - 05:53 PM

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.theevento...g_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.


How to make over $600 a day from AdSense? Discover EXACTLY how he does it in these videos:
http://www.adsense-online.com

#2 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,021 posts

Posted 30 August 2006 - 07:59 PM

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

echo "<input type='checkbox' name='sub[]' value='$id'>";

As only check checkboxes are posted you can then save the users' requirements with

<?php
foreach ($_POST['sub'] as $subcat) {

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

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users