473,395 Members | 2,079 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

MySQL Table Name

TheServant
1,168 Expert 1GB
Hey guys, a bit of a joint post with MySQL, but I though I'd try here first.

I am planning on making an online game, but there will be different ages. So my first will be Age 0 (a0) and second Age 1 (a1) etc...
Creating the tables like "a0_user_info" will be easy, but I would like to have one registration form, so that you can choose which age you are registering with. The problem comes when I am inserting the submitted data into the correct tables:
[PHP]mysql_query("INSERT INTO user_info(user_name)
VALUES('$submitted_name')")
or die(mysql_error());[/PHP]

I would like to have something like:
[PHP]mysql_query("INSERT INTO $age.'_user_info'(user_name)
VALUES('$submitted_name')")
or die(mysql_error());[/PHP]

Which should submit the data to table a0_user_info in the case of the user registering to Age 0. So is that INSERT INTO syntax possible? It doesn't work, so I am not too confident.

I might have to make new variables where I join the strings prior to calling them from the database with a new variable, but I would prefer not to and figure out the syntax to do it in one line like I've tried above.
Apr 6 '08 #1
6 1293
Atli
5,058 Expert 4TB
Hi.

That could be as simple as:
Expand|Select|Wrap|Line Numbers
  1. $age = "a0";
  2. $sql = "INSERT INTO {$age}_user_info ETC...";
  3.  
Apr 6 '08 #2
Atli
5,058 Expert 4TB
Just occurred to me...

Would it not be simpler to have all ages in the same table and having an Age column, specifying the age?
Apr 6 '08 #3
coolsti
310 100+
To the OP:

your syntax is wrong, and Atli pointed out an example with correct syntax. You were close, but you have some single quotation marks that should not be there in your query.

Basically when you have a problem like this, you should open up a MySQL console window (or using whatever direct access to mysql is available to you) and copy and paste your query with the PHP variables substituted for acceptable values, and then see if MySQL accepts your query or informs you that there is a syntax error.

You can do this by adding a line like echo $query to your code and then you will see in the browser what your query statement has evaluated to, and then copy and paste this into the mysql console.

In your case, you would then see right away that there is a syntax error, and having the actual query statement echoed to the screen may make it clear to you why.

Steve, Denmark
Apr 6 '08 #4
Markus
6,050 Expert 4TB
Just occurred to me...

Would it not be simpler to have all ages in the same table and having an Age column, specifying the age?
This makes alot more sense to me, TS.

Unless you have reasons for having seperate tables?

Markus, England.

;)
Apr 6 '08 #5
TheServant
1,168 Expert 1GB
This makes alot more sense to me, TS.

Unless you have reasons for having seperate tables?

Markus, England.

;)
Thanks for your help guys. The reason I don't have it all in one table is the ages will not be running simultaneously, more that I will leave old ages running even after the new one has started. So if I make changes to variables (adding new ones/getting rid of old ones) it will not affect previous ages. So if I have tables for each age, then they are isolated and I can make any changes I want to specific ages.

Very helpful syntax Atli. Thanks for your suggestion coolsti, I did try that in a few different ways, but didn't guess to try the '{' characters, so that's why I came here!

TS
Apr 6 '08 #6
coolsti
310 100+
Good to hear you also tried to debug the query with entering it to mysql directly. That will be a tremendous amount of help when your queries become complicated, not only for debugging syntax but for seeing how long the query takes and if needed optimizing the query.

Just FYI, you could also have done the following instead of using brackets, but I myself like to use the bracket idea:

Expand|Select|Wrap|Line Numbers
  1. $age = "a0";
  2. $sql = "INSERT INTO " . $age . "_user_info ETC...";
  3.  
Apr 7 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Gordon | last post by:
I have 2 tables t and t1. In this case, t1 is a copy of t. I want to delete rows from t1 based on criteria on the t table and a relationship between t ad t1 (in this case the id column). In the...
4
by: Ka | last post by:
I install a mysql server in default installation with latin charset, but I want to use GBK(a chinese charset), so that I can store and search chinese words directly. so, I download, unpack and...
0
by: Mike Chirico | last post by:
Interesting Things to Know about MySQL Mike Chirico (mchirico@users.sourceforge.net) Copyright (GPU Free Documentation License) 2004 Last Updated: Mon Jun 7 10:37:28 EDT 2004 The latest...
1
by: jlee | last post by:
I'm pretty much a newbie on mysql, and I need some help. I am running mysql Ver 12.22 Distrib 4.0.24, for portbld-freebsd5.4 (i386) on a server hosting an active website. The site's developer...
3
by: Juan Antonio Villa | last post by:
Hello, I'm having a problem replicating a simple database using the binary log replication, here is the problem: When the master sends an update to the slave, an example update reads as follows:...
6
by: fpcreator2000 | last post by:
Hello everyone. I'm having problems with a page I've created that is used to insert data into a database. It uploads two files into two distinct folder, and it takes the filenames and inserts...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
1
ssnaik84
by: ssnaik84 | last post by:
Hi Guys, Last year I got a chance to work with R&D team, which was working on DB scripts conversion.. Though there is migration tool available, it converts only tables and constraints.. Rest of...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.