Jump to content

Auto ID for events


Bradley99

Recommended Posts

So, I have a table in my DB, Betting. It's for a kinda fantasy pick'em/betting game. My table is as follows. . .(It's for MMA).

 

bet_id match_id user_id fighter_id method round bonus

 

Now, I need to have a different MATCH ID for EVERY fight that users pick for. So Guy1 vs Guy2 the Match ID is 1. Guy3 vs Guy4 the Match ID is 2. I need it to be this so when I update the results of the fights, I can do IF match_id = '2' AND fighter_id = '1' UPDATE. . . . .

 

How can I make so this happens? ANY help is appreciated. (Please bare in mind, I'm using no CMS or anything, I have created a very basic Admin back-end.)

Link to comment
Share on other sites

I already have auto incrementing on the bet_id table though? Any idea's? I suppose I could ENTER my own match ID when i create the fights, Silva vs Sonnen = 'slvavssonen' type thing, It's just then keeping up with them making sure i dont repeat.

Link to comment
Share on other sites

You're losing focus.

 

We talked about this the other day - you need several tables, because each table represents a set of data.  The data set from those tables needs to be unique, and the easiest way to accomplish this is to give them an *_id that auto increments.  You can positively identify data with this id, and reference it in other tables just as easily.  There's nothing you need to do to manually ID it.

 

In your bet table:

[*] bet_id is an AI row unique to this table

[*] match_id is the AI ID for the match your users are betting on

[*] user_id is the AI ID for the user who's making the bet

[*] fighter_id, method, round, and bonus are the values the user has chosen that corresponds to the match_id above

 

This is what and why they call it a relational database.  All of these items correspond / relate to one another through various methods.

Link to comment
Share on other sites

Assuming you have phpMyAdmin for database management, when you create a table and are given the opportunity to create the columns for said table, you are presented with a wide variety of properties.  One of those properties is going to be a checkbox for Auto Increment.

Link to comment
Share on other sites

I have no idea how to auto increment two columns in 1 table though?

 

You don't need (and can't have) two auto-increment ids in a single table. Each table can have one auto-increment ID and then you use those keys in other tables to relate the data. In your first post you stated you had a table with the following fields:

 

    bet_id  match_id  user_id  fighter_id    method  round  bonus

 

Assuming that is the bet tables then those fields should be something as follows:

 

bet_id (auto-increment field for this table)

match_id (a foreign key of the auto-increment field from the matches tables)

user_id (a foreign key of the auto-increment field from the users tables)

fighter_id (a foreign key of the auto-increment field from the fighters tables)

method (???)

round (a numeric field)

bonus (assume this is a float field for an amount)

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.