Okay, I've created an admin panel where I can update and delete users. Only problem is, is that I have information stored in several tables for user information. I have successfully worked out an innerjoin for recalling user information from two table, thanks for some of ya on here YAY But how do I go about deleting the user information from MORE than 2 tables? Here's the tables that I have user information stored in.
business
farms
inventory
locations
logs
rankings
stats
user
store
unit
weapon
If we're talking about an innerjoin for delete, well, I'm gonna die LMAO! Doing two at once was good enough for me LOL. Would it be best just to leave that information there after their username is deleted? Any suggestions or info? Thanks.
Last edited by Epiales on Fri Aug 30, 2013 9:22 am, edited 1 time in total.
DELETE FROM
business
farms
inventory
locations
logs
rankings
stats
user
store
unit
weapon
USING user
INNER JOIN business ON user.id = business.id
INNER JOIN farms ON user.id = farms.id
INNER JOIN inventory ON user.id = inventory.id
INNER JOIN locations ON user.id = locations.id
INNER JOIN logs ON user.id = logs.id
INNER JOIN rankings ON user.id = rankings.id
INNER JOIN stats ON user.id = stats.id
INNER JOIN store ON user.id = store.id
INNER JOIN unit ON user.id = unit.id
INNER JOIN weapon ON user.id = weapon.id
WHERE user.id = '1';
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
function DeleteUser($userID)
{
SQLQUERY("DELETE FROM `business` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `farms` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `locations` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `inventory` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `logs` WHERE `ID`='$userID' ");
(...)
}
Then in the admin panel on a click of a button it would be as simple as calling DeleteUser($userID); and that user is gone from your table.
To get all info a similar function can be used that could create arrays for each table for that specific user then you would call the function and after that all the arrays variables would be created and able to use.
DELETE FROM
business
farms
inventory
locations
logs
rankings
stats
user
store
unit
weapon
USING user
INNER JOIN business ON user.id = business.id
INNER JOIN farms ON user.id = farms.id
INNER JOIN inventory ON user.id = inventory.id
INNER JOIN locations ON user.id = locations.id
INNER JOIN logs ON user.id = logs.id
INNER JOIN rankings ON user.id = rankings.id
INNER JOIN stats ON user.id = stats.id
INNER JOIN store ON user.id = store.id
INNER JOIN unit ON user.id = unit.id
INNER JOIN weapon ON user.id = weapon.id
WHERE user.id = '1';
This makes sense Thanks! I will have to experiment.
function DeleteUser($userID)
{
SQLQUERY("DELETE FROM `business` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `farms` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `locations` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `inventory` WHERE `ID`='$userID' ");
SQLQUERY("DELETE FROM `logs` WHERE `ID`='$userID' ");
(...)
}
Then in the admin panel on a click of a button it would be as simple as calling DeleteUser($userID); and that user is gone from your table.
To get all info a similar function can be used that could create arrays for each table for that specific user then you would call the function and after that all the arrays variables would be created and able to use.
You should definetly go with vitinho444's suggestion if it's going to be sort of part of the Administrative functionality.
Creating a function/page dedicated for the deletion, one table and one query is much more easy to administer in long run.
However, if you need to do a development fast sweep of database to avoid truncation, that's when you can use a innerjoin deletion. Otherwise it is highly NOT recommended
Why so serious?
Business Intelligence, Data Engineering, Data Mining
PHP, HTML, JavaScript, Bash/KornShell, Python, C#, PL/SQL
MySQL, DB2, Oracle, Snowflake
Pentaho, DataStage, Matillion, Unity3D, Blender
if(isset($_POST['delete'])){
$tables = array('user', 'stats', 'locations');
foreach ($tables as $table) {
$DeleteQuery = "DELETE FROM $table WHERE id='$_POST[hidden]'";
mysql_query($DeleteQuery);
};
};
*EDITED* Yeah, tried and tested. Works fine. Just have to put all the tables with the same userid in there and then it will delete them all at once. YAY
vitinho444 wrote:I never worked with innerjoin, thats why i cant really say i know MYSQL or any language.. i know how to use them for what i use them, that's it..