Jump to content

PHP and MySQL databases


Aeterna

Recommended Posts

Hello,

 

I'm currently trying to make a tracking program, which grabs a users experience from a website and inserts it into an MySQL database, I have that all working fine, but I'm kind of stumped on something.... I would like to be able to make it so that multiple trackers can be in play at one time, and multiple databases(?) would be used to hold the data.  Currently, what I have now, is "mron_tracker" as my database, "xxx" (1-25, all different words) are tables, and then the username and experience are held within the table.  What I'd like to do, or know how to do, is make it so that a new database "mron_tracker_x" is created when creating a new tracker.  I'd like it to work so that, when one tracker is created, its id is "1", the next one is "2", after that is "3", and so on.

 

Here's a picture of how the structure is in PHPMyAdmin:

3oYd.png

 

If someone could point me in the right direction as to what I should look for, I'd be extremely greatful.  If you need anything cleared up let me know and I'll do my best to explain it.

 

Thank-you in advance,

Ron

Link to comment
Share on other sites

You want to create a whole new database for each tracker? Why not just add a 'tracker_id' column or something like that to these tables?

I need for there to be a separate database for each tracker because they're all different, and there's going to be quite a few of them.  If I was going to add a new column, and was to make it 'username_id', 'experience_id', how would I assign new ids to be 1 higher than the previous column?

 

Meaning, the first tracker is 'username_1', 'experience_1', then 'username_2', 'experience_2', and so on.

Link to comment
Share on other sites

Create a table like this

 

table_trackers

-------------------------------------------------

id (INT AUTO_INCREMENT PRIMARY KEY)

username (e.g. VARCHAR(255))

experience (whatever type this will be)

 

Just add new row for each tracker.

 

Sounds terrible that you would have to make a new database for every new entry. Totally terrible.

Link to comment
Share on other sites

Create a table like this

 

table_trackers

-------------------------------------------------

id (INT AUTO_INCREMENT PRIMARY KEY)

username (e.g. VARCHAR(255))

experience (whatever type this will be)

 

Just add new row for each tracker.

 

Sounds terrible that you would have to make a new database for every new entry. Totally terrible.

I see, so if I was to use an auto increment, how could I match the username and experience to that id? I'm sorry if the question is really silly, I've never really done MySQL so I don't completely understand tables/rows/columns (they all seem like the same thing to me).

 

The only way I know how to do stuff is to execute the query, such as this (may not be the best way but it's the best way I could think of):

function startTracker($database) {
global $skills, $participants;
for ($i = 0; $i < count($participants); $i++) {
	for ($a = 0; $a < count($skills); $a++) {
		mysql_query("INSERT INTO $skills[$a] (username, experience) VALUES ('$participants[$i]', '" . getStats($participants[$i], $a, 2) . "')");
	}
}
}

 

Then I grab it by:

function grabExperience($user, $table) {
while ($row = mysql_fetch_array(mysql_query("SELECT * FROM $table WHERE username='" . $user . "'"))) {
	return $row['experience'];
}
}

Link to comment
Share on other sites

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.