When a lecture (a row in ‘lectures’ table) is deleted, it is moved into the ‘lectures_deleted’ table. This acts as a sort of back-up. In this case, I need to be able to call from both of these tables, so I would like to get the data from the ‘lectures’ table, though if it does not exist here, I would then like to get it instead from the ‘lectures_deleted’ table.
The code below currently breaks the website. Any help will be much appreciated!
function getModuleCode($id){
$result = mysql_query('
IF EXISTS
(SELECT * FROM lectures WHERE lecture_id="'.$id.'")
ELSE
SELECT * FROM lectures_deleted WHERE lecture_id="'.$id.'";
')
or die(mysql_error());
$row = mysql_fetch_array($result);
return $row['module_code'];
}
How about:
This way will also select from the lectures_deleted if it is still present in the lectures table, but according to your description i believe this should not happen.
Alternatively, I would suggest to use a ‘deleted’ flag (one bit field) in the lectures table, indicating whether or not the lecture has been deleted. This way you do not need to move a deleted entry to another table.