Home : General : Databases and SQL :

General: Databases and SQL: Re: [barryb12000] move data from 1 table to another with PHP: Edit Log

Here is the list of edits for this post
Re: [barryb12000] move data from 1 table to another with PHP
Rather than deleting the NFL player from the table (players), I am assuming you are going to print that player's details somewhere in your scripts, I would recommend that you simply use codes in your scripts to check to see if that "PlayerID" exists in the USERS table, rather than moving the data into the USERS table.

Basically, it is a 1<->1 connection between PLAYERS and USERS based on the PlayerID.

Example:

PLAYERS: (tbl_Players)

PlayerID (INT, AUTO-INCREMENT, PRIMARY)
Player_First_Name (TEXT, NOT NULLl)
Player_Last_Name (TEXT, NOT NULL)

USERS: (tbl_Users)

UserID (INT, AUTO-INCREMENT, PRIMARY)
User_First_Name (TEXT, NOT NULL)
User_Last_Name (TEXT, NOT NULL)
PlayerID (INT) - [FK_KEY from Players table]

Then in your "player" selection menu, all you have to do is JOIN the two tables and ONLY show records from the Players table that ARE not FK_KEYS in the USER table.

Example:

Quote:

SELECT tbl_Players.Player_First_Name, tbl_Players.Player_Last_Name, tbl_Players.PlayerID
FROM tbl_Players
WHERE tbl_Players.PlayerID NOT IN (SELECT PlayerID FROM tbl_Users)
ORDER BY tbl_Players.Player_Last_Name


Of couse, you'll need to be using a DB app that supports sub-queries, but you can also re-write the above SQL statement without the subquery to accomplish the same task.

Then in your HTML select menu codes, depending on what web app or language you are using, all you have to do is output the following columns in the select menu (of course, looping through the query):

tbl_Players.PlayerID
tbl_Players.Player_First_Name
tbl_Players.Player_Last_Name

EXAMPLE (with Perl template parser, like GT's):

Quote:

<select name="PlayerID" size="1">
<option value="">Choose a Player</option>
<option value="<%PlayerID%>"<%Player_First_Name%> <%Player_Last_Name%></option>
</select>


Of course, I've left out the loop codes since they can be written and applied in quite a few ways.

Hope this makes sense and helps.
========================================
Buh Bye!

Cheers,
Me

Last edited by:

Stealth: Jun 17, 2002, 10:07 PM

Edit Log: