homepage Welcome to WebmasterWorld Guest from 54.161.175.231
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Deleting from multiple tables
query issues in php
femiot




msg:4430445
 10:42 pm on Mar 17, 2012 (gmt 0)

Course table
cid(course id)
cname

course_student table
sno(student id)
cid(course id)

Student table
sno(student id)
name

Hello peeps! I need your help on this one... the query i need is when i delete the record from course table it should delete all the records where that cid = sno in course_student(without leaving orphans) and where sno of course_student = sno of student at once! (php5 and mysql)

Thanks

 

femiot




msg:4430447
 11:55 pm on Mar 17, 2012 (gmt 0)

$result = " SELECT * FROM course, course_student, student WHERE course.cid = course_student.cid AND course_student.sno = student.sno AND course.cid = '$cid'";
$result = "DELETE course,course_student,student FROM course LEFT JOIN course_student ON course.cid = course_student.cid LEFT JOIN student ON course_student.sno = student.sno WHERE course.cid = '$cid'";

Sorted it out myself cheers!

coopster




msg:4437794
 12:44 am on Apr 6, 2012 (gmt 0)

Good for you femiot! Glad you got it sorted. Now you can dig into a neat little database feature called "triggers" ... always more to learn :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved