Jump to content

Recommended Posts

What I'm trying to achieve is:

 

I create a new announcement for my game. When players login the game they are right on the announcement page. The new announcements I want displayed in red, and once they've read it, the announcement would go back to normal color.

 

Each player is specified by an ID. I want the database to update a TEXT with their ID.

Like so:

 

Player 1 reads it

Player 2 doesn't

Player 3 reads it

 

so in the database the the "has_read" value would update the type "TEXT" to this:

1,3

 

After it's stored, how would I display it correctly, for example, (completely incorrect since the players ID isn't 1,3)

 

if (announcements->has_read == players_id)

{

display red announcement

}else{

display normal since they've read it

}

 

 

Any help would be greatly appreciated, I hope I made this easy to understand :)

Google "normalization". You don't want to store the data as a delimited list.

 

I'm not too sure what that means :X

If it means don't store it with a comma, I could do (1)(3) as my values being set.

But if it means not to store it the way I wanted, how could I have each individual player be stored as if they read the announcement or not?

Slyte: It means exactly what she said: "Google (database) normalization". It will give you lots and lots of guides on how to properly structure your data, to accomplish what you want.

 

stijn: I think you might want to do the same. Will give you lots of useful information.

Edited by Christian F.

Let me elaborate. You should not store delimited ids in a text field as you will end up with a mass of issues down the line. To normalize your database you need to do the following (I am guessing your table / field names)

 

players

=======

player_id (int)

name (vc 50)

 

announcements

=============

an_id (int)

content (vc 255)

 

players_to_announcements

======================

id (int)

player_id (int)

an_id (int)

date_read (datetime)

 

So if you have 3 players in the players db table with ids 1, 2, and 3 and you have an announcement in the announcements table with an id of lets say 456, if a player reads an announcement you record this by storing a record in the players_to_announcements table. If player id 2 & 3 have read the announcement the data will look as follows:

 

1 | 2 | 456 | 2013-01-01 01:00:00

2 | 3 | 456 | 2013-01-01 02:00:00

 

You can then easily query this data to find what players have read each announcement

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.