Jump to content

Table Creation


Recommended Posts

Guest jahotchk
Posted

Hello Everyone... I hope I can leverage the expertise here to help me solve a problem I am having creating my database for my World of Warcraft guild.I have a 2 Tables.char_tblrace_tblIn char_tbl I have a number of columns. One column I have is to allow a player to define the character race he/she has chosen to play. Instead of having the player type in the name of the race, I would like them to be able to choose from a list of options.I also created the char_tbl with a series of columns, one column, c_race has been defined using the following syntax:CREATE TABLE char_tbl (`c_race` VARCHAR( 10 ) DEFAULT 'Character Race' NOT NULL ,);Lastly, I created the race_tbl with one column using the following syntax:CREATE TABLE race_tbl('a_race" VARCHAR(10) DEFAULT 'Choose Character Race' NOT NULL,PRIMARY KEY ('a_race'),);a_race has the following values:OrcUndeadTrollTaurenBlood ElfWhat I am hoping to accomplish through a web page is a drop down list populated with the values in a_race, but be inserted into the c_race column of the char_tbl. Can someone please share with me how I accomplish this goal? Thank you,Jason H.

Posted

Well, I can't tell you how to populate your dropdown list. But as far as taking the contents of one table and using them to insert into another, you have a few different options.1. Try

INSERT INTO char_tbl (c_race)SELECT a_race FROM race_tbl WHERE a_race = ***What the user chose from the dropdown***

2. If you are using MS SQL, then you could also use variables to do this (I know that MySQL, and Oracle also allow this but I am unsure of their syntax)For MS SQL

@Race     VARCHAR(10)SELECT @Race = a_race FROM race_tbl WHERE a_race = ***User Input***INSERT INTO char_tbl (c_race)VALUES @Race

Or maybe even just:

@Race = ***User Input***INSERT INTO char_tbl (c_race)VALUES @Race

As I mentioned before, not sure how you will get the dropdown list populated, but this should help you once you get past that point.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...