PHP/MySQL: How do I find orphaned records?

From: Date: Wed, 30 Aug 2000 05:01:53 +0000
Subject: PHP/MySQL: How do I find orphaned records?
Groups: php.db 
Request: Send a blank email to php-db+get-2469@lists.php.net to get a copy of this message
Hi, I have a database with two tables. One is called course_type, and the other is called course. Each course is assigned a course type by the user. The user can insert or delete course types, so is able to delete a course type that still has courses attached to it. Once they do this, all of the courses that were once attached to that type become orphaned. I would like a list of these orphaned courses to be displayed to the user, so they can reattach course types to them or delete them if they like. I have two ideas in mind: 1. Write some SQL query that finds all of the orphaned records and returns a result array. I believe this is either difficult, messy or impossible. 2. Write some PHP function that locks the table, and marks each course that is attached to the type that is about to be deleted. I would then write an SQL query that found all of the marked courses, and return a result array. What is the best way to accomplish this in PHP/MySQL? Thank you, Beau

« previous php.db (#2469) next »