MySQL & PHP - select/option lists and showing data to users that still allows me to generate queries
        Posted  
        
            by Andrew Heath
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Andrew Heath
        
        
        
        Published on 2010-03-29T22:20:22Z
        Indexed on 
            2010/03/29
            22:23 UTC
        
        
        Read the original article
        Hit count: 470
        
Sorry for the unclear title, an example will clear things up:
TABLE: Scenario_victories
ID  scenid        timestamp      userid side    playdate
1   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
2   RtBr001   2010-03-15 17:13:36   7     1     2010-03-10
3   RtBr001   2010-03-15 17:13:51   7     2     2010-03-10
ID and timestamp are auto-insertions by the database when the other 4 fields are added.
The first thing to note is that a user can record multiple playings of the same scenario (scenid) on the same date (playdate) possibly with the same outcome (side = winner). Hence the need for the unique ID and timestamps for good measure.
Now, on their user page, I'm displaying their recorded play history in a <select><option>... list form with 2 buttons at the end - Delete Record and Go to Scenario
My script takes the scenid and after hitting a few other tables returns with something more user-friendly like:
  (playdate)   (from scenid)        (from side)
#########################################################
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Germany, Hungary won #
# 2010-03-10  Road to Berlin #1 -- Soviet Union won     #
#########################################################
     [Delete Record]              [Go To Scenario]
in HTML:
<select name="history" size=3>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Germany, Hungary won</option>
  <option>2010-03-10  Road to Berlin #1 -- Soviet Union won</option>
</select>
Now, if you were to highlight the first record and click Go to Scenario there is enough information there for me to parse it and produce the exact scenario you want to see. However, if you were to select Delete Record there is not - I have the playdate and I can parse the scenid and side from what's listed, but in this example all three records would have the same result.
I appear to have painted myself into a corner. Does anyone have a suggestion as to how I can get some unique identifying data (ID and/or timestamp) to ride along on this form without showing it to the user?
PHP-only please, I must be NoScript compliant!
© Stack Overflow or respective owner