Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 08:24 PM   PM User | #1
tim_poole247
New Coder

 
Join Date: Feb 2009
Posts: 13
Thanks: 1
Thanked 0 Times in 0 Posts
tim_poole247 is an unknown quantity at this point
problem selecting data from table

I have a table on my db called 'user_accounts' which stores each members info. I also have a db table called 'games' which stores data for different games on the server. Each game is identified by a 'db_name' which is stored in the 'games' table. the 'db_name' also acts as a prefix for other tables on the db specific to that game, for example 'db_name'_users. Im currently working on an Admin removal script. I can quite happily remove the Admin from the main user_accounts table. However, I need to find if that user is currently in any games, and if so delete them from the game aswell.

The main issue is because db_name is dynamic, and the script will be generic. Its part of an install utility, so the code needs to work for whatever the end user sets the db_name to.

What im trying to achieve is this:

a sql query on the 'games' table, which will give me all the 'db_name' values, and then search each 'db_name_users' table for the user. if the user is pressent then delete all entries of that user from that game. The user can be in multiple games, so it would have to delete them from all the games they are in.


I can normally figure things out via trial and error, but this is really causing me headaches, any ideas that someone can chuck at me 2 try out?
tim_poole247 is offline   Reply With Quote
Old 11-04-2012, 10:06 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,237
Thanks: 59
Thanked 3,998 Times in 3,967 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Offhand, I'd say you have a bad database design.

What purpose is there in having each game in a separate table? Are the other fields in each of the separate tables SIGNIFICANTLY different from one game to the next? If not, they should be all in one table, which would simplify not only this task but many future task a lot.

Even if there are some fields that need to exist specifically for a given game, you'd be better off pulling all the common fields together into a single table and then only do the separate tables for the significantly different fields.

Read up on "normalization."
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-05-2012, 07:22 AM   PM User | #3
Harmony.H
New to the CF scene

 
Join Date: Nov 2012
Location: Lithuania
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Harmony.H is an unknown quantity at this point
Congratulations on having one of the most sophisticated phorums I've came across in some time! Its just incredible how much you can take away from something simply because of how visually beautiful it is. Youve put together a great phorum space great graphics, videos, layout. www.codingforums.com is definitely a must-see phorum! Great!
Harmony.H is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:23 PM.


Advertisement
Log in to turn off these ads.