pacome Posted June 11, 2007 Share Posted June 11, 2007 Hi! I've got a DB with let's say 3 tables (each registered user has one)... and in each table there is let's say id, username, totalmoney, amountA, amountB... I also have one fix external paramter let's say "5"... I need to query the different tables, in such way that I multiply 5*amountA, 5*amountB, add them both to totalmoney into a new variable let's say $totalwealth... then query the other tables and make an array with the $totalwealth values... Can this be done, in a relatively short script or do I need to write one for each table, insert into a database and then compare??? thanks for your comments and hints! Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/ Share on other sites More sharing options...
pacome Posted June 11, 2007 Author Share Posted June 11, 2007 I need to know how to query all tables, and not knowing how many tables there are because users register and they create a table with their nick... Some kind of: "SELECT * FROM *;" I don't know, I'm thinking of a loop that checks all tables, but I don't know how to tell mysql to check all tables in the DB. Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-272756 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 I've got a DB with let's say 3 tables (each registered user has one).. Why would each user have there own table? This wreaks of poor design, hence your problem. You really should look into database normalization techniques instead of using your current approach. Theres a decent tutorial here. Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-272768 Share on other sites More sharing options...
pacome Posted June 12, 2007 Author Share Posted June 12, 2007 THANK YOU! I will check this tutorial.. :-[ Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-272772 Share on other sites More sharing options...
suma237 Posted June 12, 2007 Share Posted June 12, 2007 Hope your query solved?if still have any problem please include the code Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-272972 Share on other sites More sharing options...
pacome Posted June 12, 2007 Author Share Posted June 12, 2007 Thanks... I don't have the code yet... it was more of a question to know if it can be done or not... I managed to calculate the amount of money one player has, but doing this for an unknown number of players was something I didn't know where to start with... I admit it's easier to put all players in one table and query all of them with something like $result= "SELECT 5*(AMOUNTa), 5*(AMOUNTb) FROM TBL_NAME"; then I could continue with a loop while ($row= mysql_fetch.... ...) and I could echo all results... the thing is that I had planned to give each user a different table, just to collect enough individual information, but perhaps the same can be done with one table that hold all users... But I repeat, the question was wether you can query an unknown number of tables in a DB and to get hints on how to do it... thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-273095 Share on other sites More sharing options...
trq Posted June 12, 2007 Share Posted June 12, 2007 the question was wether you can query an unknown number of tables in a DB and to get hints on how to do it... It would be a hack. Better to design the database properly in the first place, there is absolutely NO reason to give each user there own table, its just going to make your queries more difficult. Did you read that tutorial I pointed you too? Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-273162 Share on other sites More sharing options...
pacome Posted June 15, 2007 Author Share Posted June 15, 2007 I've been reading it... Thanks... I decided to make one table for the users, and one table for the special data and they only share one field (nick) so I can cross select the info... I'm quite new at programming and I do it only for fun. Right now I'm designing a game for me and some snooker friends from a msn group. Quote Link to comment https://forums.phpfreaks.com/topic/55164-query-different-tables/#findComment-275361 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.