MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 30th, 2009, 10:18 AM
colpaarm's Avatar
colpaarm colpaarm is offline
300lb Bench!
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Aug 2001
Location: New York
Posts: 2,260 colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level)colpaarm User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 19 h 29 m 29 sec
Reputation Power: 20
Problems figuring out intelligent way to set a flag

I have a chess website and there's a mygames section which, as you would expect lists users games. At the end of the game, it shows up still, but let's you see the status (who won, who lost). Once the game is over, it also shows an "archive game" link. This is where I'm having issues, surprisingly.

So I have a game table with a number of fields, including player_white and player_black. So on the mygames page, I pull up all current games for a user with

PHP Code:
 select
  
*
from
  game
where
  player_white
='{$sUser}'
or
  
player_black='{$sUser}' 


Now, the archiving part. I can, on the same game table, have fields like player_white_archive and player_black_archive. Initially, it would be set to null and when the person archives their game, set either one of these fields to 1 (or whatever) to indicate they've archived the game. The only problem with this is that for every game, the player can either be white or black. It's easy enough to figure out for a particular game, "Ok, for this game you were black, so set player_black_archive to 1. However, what sql do you use to pull up all games that have not been archived? For each game, you can be either white or black. If I knew that for every game you'd be white, for example, I could do

PHP Code:
 select
  
*
from
  game
where
  player_white
='{$sUser}'
and
player_white_archive is null 


But in some games you can be white and in others black. I've tried a separate archived_games table which has the user (either player_white or player_black) and the game id, but this approach and using a left join statement seems to cause just as many headaches. Anybody have thoughts on what I should do? Thanks in advance
__________________
Correspondence and live chess
nothingbutchess.com

Reply With Quote
  #2  
Old June 30th, 2009, 10:48 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,792 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 20 h 24 m 10 sec
Reputation Power: 2482
Code:
WHERE {$sUser} = player_white AND player_white_archive IS NULL
   OR {$sUser} = player_black AND player_black_archive IS NULL
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Problems figuring out intelligent way to set a flag


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek