Jump to content

Migrating PHP based "table" to a view or other table.


PC Nerd

Recommended Posts

Hi,

 

At the moment I've got two tables: "Sports" and "Groups"  - and I've got a PHP script editing another table which is like a "sports by group" (or "events") eg. seperating different groups of competitors (ages, disabilities... whatever the group is)...  I need the table to have a static ID for each row/"event" generated.... so I cant use a view because it cant have a primary key.

 

Is there an SQL based alternative, that will allow the same final queryable table/view but that will remove the language side of it (like creating a view with primary keys?)

 

Thanks,

PC_Nerd

Link to comment
Share on other sites

Good point....

 

two tables, I need to have a third with all of the other two table's worth of data init - linked with a Primary key....  eg:  in the new table, for each record in the groups table I would have every record from the sports table...  At the moment I can get the data like I want into a view - but those dont allow primary keys ( and understandably)..... At the moment I'm having to "start" the system by using PHP to generate each record into the new table - and then essentially lock access to the other two tables - because changing them could change the new table's data ( which is the "mission critical" thing in the system....

 

Is there an alternative method to this scripting?

Link to comment
Share on other sites

groups

--------

group_id int PK

group_name varchar

upper_limit int

lower_limit int

 

sports

-------

sport_id int PK

name varchar

 

 

data:

 

groups

-------

1, "Jnr", 12,15

2, "Snr", 16, 19

 

sports

--------

1,"High Jump"

2, "Long Jump"

 

 

so that my resulting table would be:

 

events

__________

1, 1( sport_id), 1 (group  id)

2, 1, 2

3, 2,1

4,2,2

 

 

At the moment I can acheive a similar thing in a view - however the events table cannot have the primary key .... can I get a primary key in there somewhere?

Link to comment
Share on other sites

events is the resulting table..

 

I'm trying to join the groups and sports together, so that the event table contains every sport for every group - with a uid so that I can reference it with point counts etc.... ?

Link to comment
Share on other sites

I'm not sure what you mean by the "INSERT INTO... SELECT...". (as in I know the SQL.. but not what its talkign about table wise).....

 

the events table/view/whatever needs to have a static id to each group/sport id combination ( as I showed in the example events table).... thanks

Link to comment
Share on other sites

I'm not sure what you mean by the "INSERT INTO... SELECT...". (as in I know the SQL.. but not what its talkign about table wise).....

You can use the resultset from one query as the input for another... the refman has examples.

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.