Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2003
    Posts
    37

    Unanswered: Inserting data from a table ? is this possible.

    Hi I need pushed in the right direction as I'm struggling to get my head round a problem. Any suggestions appreciated.

    I am designing a site for the golf society I'm part of and have come to a dead end. I used to run a site years ago and had a good understanding of php and now it’s all gone out of my head.

    The problem is I have about 16 people and after each match they need a score put against them. This has to be put in a database so I can use this data as part of a later script to alter everyone’s handicap based on their score and position in the game.

    So basically how can I display all members and then give them a score?


    Thanks

    JD

  2. #2
    Join Date
    Feb 2004
    Posts
    533
    Quote Originally Posted by JD|
    Hi I need pushed in the right direction as I'm struggling to get my head round a problem. Any suggestions appreciated.
    JD
    At this point in your project you have to start by answering the most basic questions.

    What platform will you use?
    How much work and effort are you going to apply?
    What are your skills?
    Do you have a server with PHP / MySQL?

    Maybe with just 16 people and after you answer these questions you will just want to keep it simple and use HTML Only. List your team members with the scores and make a new page for each game? But this is the dbForum PHP board, so lets assume you have you mind set on using PHP/MySQL.

    You want to divide the project in two parts: 1. Data 2. Display or User Interface (UI).

    Start with data. Identify your Entities, tables - fields - relationships. I like to sketch this out, even for a simple projects. Start with a paper and pencil or draw it out on a white board so you can erase and make changes as you go. After you get it refined on paper you can transfer it to a Visio ER Diagram as an option. Here is a good example from the databaseanswers.org Web site: Physical Data Model for Golf Tournaments
    Once you have the conceptual drawing of the data you can create your database. Create your tables with indexes and fields based on your design model. (You will use a database editing program to work with the database, this should be part of your development toolset) After you have the database, tables, fields and relationships set you will add some sample data.

    You should already have some basic ideas about the user interface pages needed to maintain your data and display information. Most likely you will need some access control interface to restrict users and hackers from getting into the admin pages and changing your data.

    To actually get down to the coding of this the best way to learn is by example. Search for sample code and look at the source code of some php programs with features you like or want in your program then adapt this for your program.

    You can use your database editor to Test SQL queries first, then copy the SQL into your php code to use in your program.

    Does that help?
    ~

    Bill

  3. #3
    Join Date
    Dec 2003
    Posts
    37
    I have the tables all planned out and normailised. My big problem is I can display a list of members with there Unique ID but I don't know how to make a form that will let the user add a score for each member i.e.

    1 PlayerA 37
    2 PlayerB 29
    3 PlayerC 32
    4 PlayerD 31

    I want to be able to store the user ID,Their Score and a Match ID.

    Thanks

    JD

  4. #4
    Join Date
    Jul 2004
    Location
    Dundee, Scotland
    Posts
    107
    I think you can imagine the solution if you had single form to update the score for one player. the form would have the fields: userid, playername, matchid, and an empty text field for score. when the form is submitted you'd form an SQL statement to insert the player's match score into the appropriate database table.

    to show a form listing multiple match players, its the same as I describe above, but append a unique number to each form fieldname... so you'd have:
    userid1, playername1, score1.
    userid2, playername2, score2.
    etc.

    note that the matchid would be a single hidden field in the form.

    now because you are generating a form based on the players of that game via a database query, when the form is submitted you might not be sure how many variables/players to process. you might query the database again to count how many players are in that game, or you might store this in another hidden form field.

    now you'd dynamically build each variable string in a loop based on how many players are in the game e.g. "userid".$counter would access form field "userid1".

  5. #5
    Join Date
    Feb 2004
    Posts
    533
    Essentially you will have a table containing the Match scores, matchID, userID of each player. You will load a record for each player into the table with a null score to start. You will generate a list of players in a table form with a text field to add the score. An update button on the form will run a process to loop through each row of the table and build an array of the userIds and Scores. Then use a while loop to send an Update query for each userID to update the table with the Match Score data. Then after the updates are complete the page will refresh to show the changes.

    The SQL will look something like this:
    UPDATE tblmatchscore SET score = $tbluserscore where userid = $tbluserid and matchid = $matchid;

    You may want to check out some examples. "Browse Edit" is an abstraction framework PHP package which I have tested. Its posted on PHPclasses.org. You may want to take a look at this to see some examples or use with your project. http://www.phpclasses.org/browse/package/1547.html
    ~

    Bill

  6. #6
    Join Date
    Dec 2003
    Posts
    37
    Thanks both of you have helped me get my head round this one. I have a clear idea of what I want now the difficult part is getting the code sorted and error free!!


    Thanks JD

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •