Jump to content


Photo

does anyone know the best way,


  • Please log in to reply
2 replies to this topic

#1 blanktarget

blanktarget
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 November 2003 - 04:38 PM

I have form data where one field is a multiple select. I\'ve set up a table for the multiple select data-\'group\', I have a table for the rest of the data-\'listing\'. I have a third table-\'link\' which has the primary keys from each of the other tables, group_id and listing_id, because I need each client\'s listing, which is phone, name, etc. to correspond with all of the groups that they select in the form.

I have this layyed out as a script but it seems messy and I don\'t know if it will work as the database grows

after connection and form validation:

insert into table listing (column_1, etc) values ($name, etc)
select * from listing order by \'listin_id\' limit 0, 1 //to get the last row?

and then insert the groups selected with the listing_id for reference into the \'link\' table. Somehow this seems like it\'s almost there. That multi select is killing me, this should be easy.
It\'s not that I don\'t know how to do it, i just haven\'t learned it yet.

#2 Barand

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

Posted 04 November 2003 - 08:45 PM

When you have a multiple select, give it an array name, like \'group[]\'

When you process the form

[php:1:491fe48a91]<?php
$groups = $_POST[\'group\'];

foreach ($groups as $group) {
# insert a group record for value $group
}
?>[/php:1:491fe48a91]
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

#3 blanktarget

blanktarget
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 04 November 2003 - 09:20 PM

will that put each group into the same field in the db?
It\'s not that I don\'t know how to do it, i just haven\'t learned it yet.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users