Add to Muliple Tables

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
cupaball
Forum Commoner
Posts: 85
Joined: Sun Feb 12, 2006 1:46 pm

Add to Muliple Tables

Post by cupaball »

Hi All:

Here is my issue: I will have the following tables:

Venue:
ID | Name | Demographics


Venue Type:
ID | Title|


Venue by Type:
Venue ID | Venue Type ID

My question is if I have form used to enter enter a venue with muliplte venue types (check boxes), what is the theory behind adding adding info to the Venue by Type Table?

As it stands now, I only have 2 tables, Venue and Venue Type, but I can only have a one to one match.
thinsoldier
Forum Contributor
Posts: 367
Joined: Fri Jul 20, 2007 11:29 am
Contact:

Re: Add to Muliple Tables

Post by thinsoldier »

This might not be the best way but it's how I do it.

If you're creating a new venue, after it's inserted grab it's id number (mysql has get_last_id mysql function or something)
then using that id add it and each selected venues to your venue by type table
Warning: I have no idea what I'm talking about.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Add to Muliple Tables

Post by Christopher »

You can also use what is called a Sequence to generate an ID to use as the key for all records. Some databases like Oracle and Postgres support Sequences, others like MySQL you need to emulate them with a table with an autoincrement column.
(#10850)
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Add to Muliple Tables

Post by josh »

cupaball wrote:what is the theory behind adding adding info to the Venue by Type Table?
As it stands now, I only have 2 tables, Venue and Venue Type, but I can only have a one to one match.
Many to many associations are typically done with association tables
Post Reply