LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2005, 06:39 AM   #1
ALInux
Member
 
Registered: Nov 2003
Location: Lebanon
Distribution: RHEL 5/CentOS 5/Debian Lenny/(K)Ubuntu Is Dead/Mandriva 10.1
Posts: 676
Blog Entries: 7

Rep: Reputation: 32
MySQL "insert into two tables"


Hi...
Iam creating a database for the music club I belong to. "PHP +MYSQL" Ive studied databases but I have problems with the implementation.

I have two tables one called users with a uid as a primary key. And another table called schedule with sched_id as the primary key.

The registration input form contains a a schedule through which the user can choose his schedule...and he has to enter email address etc..

Then I do the following:

$sql= "INSERT INTO users(name,major,phone,email,address,instrument) ".
"VALUES('$name','$major','$phone','$email','$address','$instrument')";
@mysql_query($sql) or die(mysql_error());

The question is : Now that Ive entered the data for the user how do I insert his schedule in a manner that links them together. Ive added "uid" the primary key of the user table to the schedule table.
 
Old 12-17-2005, 07:08 AM   #2
jamie_barrow
Member
 
Registered: Jul 2003
Location: Gauteng, South Africa
Distribution: Windows XP, yup :D Will be back onto Ubuntu probably someday
Posts: 107

Rep: Reputation: 15
If you have the schedules primary key in the users table, then it links them together, i.e.

users
-----
uid (primary key)
sched_id (foreign key)
etc...

Then when you create a schedule for a user, you insert its primary key in the relevant user's record. Then when you select * from users where sched_id = some_value and uid = your_user, you will get the users data for the schedule, or if you have a user, first get the schedule id from the user table then search the schedule table for that id. Im not so good with SQL syntax but hope you get the idea
 
Old 12-17-2005, 07:10 AM   #3
jamie_barrow
Member
 
Registered: Jul 2003
Location: Gauteng, South Africa
Distribution: Windows XP, yup :D Will be back onto Ubuntu probably someday
Posts: 107

Rep: Reputation: 15
I think theres a JOIN function of SQL that might help in doing what you want? As i always say, google it
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Buzilla issue: "Can't connect to local MySQL server through socket '/tmp/mysql.sock'" vitopn Linux - General 3 05-21-2007 10:13 AM
DBI perl "insert" problems Xris718 Programming 3 02-09-2005 03:33 PM
PHP "for.. loop" to insert into mysql Boby Programming 10 05-29-2004 10:07 AM
MySQL setup stops at command "./configure --prefix=/usr/local/mysql" k41184 Linux - Software 1 05-20-2004 02:44 PM
MySQL won't start "Can't open privilege tables" atom Linux - Software 0 04-20-2004 03:05 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration