MySQL Forums
Forum List  »  Newbie

Re: multiple select and one insert?
Posted by: Barry Galbraith
Date: November 28, 2010 01:49AM

DROP TABLE IF EXISTS `enrollment`;

CREATE TABLE `enrollment` (
  `enrollmentNum` int(11) NOT NULL AUTO_INCREMENT,
  `studID` int(11) DEFAULT NULL,
  `sessionID` int(11) DEFAULT NULL,
  `facID` int(11) DEFAULT NULL,
  `courseID` int(11) DEFAULT NULL,
  `classroomID` int(11) DEFAULT NULL,
  PRIMARY KEY (`enrollment_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;


$instudID=$_POST['inputstudID']; 
$incourseNum=$_POST['inputcourseNum']; 
$infacID=$_POST['inputfacID']; 
$insessionID=$_POST['inputsessionID']; 
$inclassroomID=$_POST["inputclassroomID"]; 


mysql_query ("INSERT INTO enrollment VALUES (NULL,".$instudID.",".$insessionID.",".$infacID.",".$incourseNum.",".$inclassroomID.");

To display the data for student 86
SELECT e.enrollmentNum
      ,s.studID
	  ,s.fname
	  ,s.lname
	  ,c.courseNum
	  ,c.days
	  ,c.time
	  ,c.description
	  ,c.credits
	  ,f.facID
	  ,f.ffname
	  ,f.flname
	  ,t.sessionID
	  ,t.session
	  ,l.classroomID
	  ,l.building
FROM student s
JOIN enrollment e
ON e.studID = s.studID
JOIN course c
ON c.courseNum = e.courseID
JOIN faculty f
ON f.facID = e.facID
JOIN term t
ON t.sessionID = e.sessionID
JOIN location l
ON l.classrooID = e.classroomID
WHERE s.studID = 86;

Good luck,
Barry.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.