Read from Database separated by a comma

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ykarmi
Forum Commoner
Posts: 35
Joined: Mon Oct 30, 2006 4:45 pm

Read from Database separated by a comma

Post by ykarmi »

Hey Guys,
I have a website, in which a user can choose to predict soccer games every week, but in order for him/her to predict the week, they need to buy it first. I have no problems with the buying part, but the data of the weeks bought should be entered into a database. I have three rows in my data base: username, pass, weeksbought.
Now, I have a page that checks what weeks were paid, it consists of a list that looks like this: (EX.1)
Week 1
Week 2
Week 3
Week 4
etc...

Right next to those values, there will be a word displayed. so say a user bought week 1 and 3 it would do this:
Week 1 Paid
Week 2 Unpaid
Week 3 Paid
Week 4 Unpaid
...

So I need to somehow check with the database whether a week was paid or not. Can the row weeksbought display numbers separated by a comma? something like this?
1,3
If so, How can I read from those weeks into the PHP file that displays what weeks were paid and what weeks were unpaid? (refer to EX. 1)

Thank you sooooo much people.
Yours,
Yuval Karmi
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I may be completely confused by your post but..

What is the maximum number values weeksbought will ever have in it? If it's at or under 32 (and these are values that every field could possible share) then you can use a SET field.

If the possible pool of values differs, but the maximum number of these values is relatively short you can use a VARCHAR.

I normally recommend using a separate table, but the maximum scope of this seems somewhat capped so it may be easier for yourself to use a single field.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

I second the SET field suggestion.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

This is a duplicate post
Post Reply