Deleting a user > need to also delete their project, and then activities for that project? (PHP, MyS
Posted
by Jamie
on Stack Overflow
See other posts from Stack Overflow
or by Jamie
Published on 2010-05-04T00:32:58Z
Indexed on
2010/05/04
0:38 UTC
Read the original article
Hit count: 615
Hi guys,
Really stuck with this... basically my system has 4 tables; users, projects, user_projects and activities. The user table has a usertype field which defines whether or not they are admin or user (by an integer)...
An admin can create a project, create an acitivity for the project and assign a user (limited access user) an activity. Therefore, this setup means that an admin is never directly associated with an activity (instead a project).
When my head admin user deletes an admin, I need all projects and activities (for their projects) to be deleted also. My delete script for a user is simple so far and works, but I'm having trouble on how to gain the projectID in order to know which activities to remove (associated with the projects which are about to be deleted):
$userid = $_GET['userid'];
$query = "DELETE FROM users WHERE userid=".$userid;
$result = mysql_query($sql, $connection)
or die("Error: ".mysql_error());
$query = "DELETE FROM projects WHERE userid=".$userid;
$result = mysql_query($sql, $connection)
or die("Error: ".mysql_error());
$query = "DELETE FROM userprojects WHERE userid=".$userid;
$result = mysql_query($sql, $connection)
or die("Error: ".mysql_error());
$query = "DELETE FROM activities WHERE projectid=".$projectid;
$result = mysql_query($sql, $connection)
or die("Error: ".mysql_error());
Now the first three queries execute fine, obviously because the userid is being retrieved successfully. However the 4th and final query I know is wrong, because there is no projectid to be gained from anywhere, however I put it there to help understand what I am trying to get!! :D
Im guessing that i would need something like 'WHERE projectid=' then something to gather the removed projects from the userid which can be related to the activities for that project(s)!! Its a simple concept but I'm having trouble...please excuse any bad code as I am learning also. Thanks for any help!
© Stack Overflow or respective owner