Jump to content

Recommended Posts

Hey all,

 

I'm trying to improve the speed of my database queries and I want to put some players IDs in a single column and seperate them by a comma.

 

So inside my colum "awaiting" I want it to be like 123,356,8678,9799 etc.

 

What's the fastest way or best way to add new IDs to this column and remove them.

 

Basically when a player joins a team they go into awaiting, then when they get approved they get removed from awaiting and added into joined with the same comma seperated IDs

[ot]I tried going down this road just recently and failed..  I guess it's just a fact.  Sticking a comma separated list of id within a column is complete no-no in web development.[/ot]

Rather than have awaiting set as a column, it needs to be it's own table.  Crazy right? No.. that's the way it's gotta be.

 

Create a table called awaiting or something relevant to what you're making and considering the information you've given us.. put 3 columns in it..  all INTs

- ID //  For the awaiting id

- TID // For the team id

- PID // For the player id

 

Now, when you have a user request to be on a team... run a query similar to this

INSERT into awaiting (`tid`,`pid`) VALUES ($desiredTeam, $currentPlayer)

To see all the players awaiting approval for a certain team.. then run this query

SELECT name.players FROM awaiting
LEFT JOIN players ON awaiting.pid = name.id
INNER JOIN teams ON awaiting.tid = teams.id
WHERE teams.name = "Bulldogs";

At least I think the above query would work... don't take my word on it.

Hey thanks for the advice.

 

That last query you posted, iv never actually seen a query like that lol, could you explain what it's doing? Left join and inner join etc?

 

If I was going to select all awaiting players I would have just done this

 

select * from awaiting where team_id=$teamid

 

what the difference between that and the complicated looking query that you just posted with joins etc?

 

Cheers!

Well.. your query would actually be the most ideal when I think about it.  For some reason I was writing it in the assumption that I didn't know the id of the team name, but obviously you would have that information.

 

The INNER JOINs and LEFT JOINs just make things easier... less queries.  You probably will use at least one JOIN before it's over with.  By using a JOIN you can SELECT not only all the awaiting player id WHERE the team = suchAndsuch..  but you can also have MYSQL select those ids... match them with their respective player names / team names.. and return that instead.

 

Say for instance, instead of a list of the awaiting ids.. you wanted a list of the actual player names.  That's the ticker right there.

SELECT players.name FROM awaiting 
INNER JOIN players ON awaiting.pid = players.id
WHERE awaiting.tid = $teamid

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.