Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/55164-query-different-tables/
Share on other sites

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.

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.

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!

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?

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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.