Solved

limit mysql insert to 22 players

Posted on 2010-08-17
10
301 Views
Last Modified: 2013-12-13
Hi,

I have been given a task to create an insert page where I can add football players into a database, I am using dreamweaver with php/mysql

I am not sure how I can do this without it being long winded.


I originally thought having 22 boxes on a page with textfields, but thats crazy.


Is there a way using dreamweaver I can disable the function of inserting players for that team.


My player table is as below





CREATE TABLE IF NOT EXISTS `player` (
  `player_id` int(8) NOT NULL auto_increment,
  `fname` varchar(100) NOT NULL,
  `sname` varchar(100) NOT NULL,
  `gender` varchar(10) default 'Male',
  `nationality` varchar(50) default NULL,
  `email` varchar(255) default NULL,
  `dob` date default NULL,
  `place_birth` varchar(255) default NULL,
  `height` varchar(20) default NULL,
  `weight` varchar(10) default NULL,
  `photo` varchar(255) default NULL,
  `comments` text,
  `position` varchar(255) NOT NULL,
  `team_id` int(8) NOT NULL,
  `Goals` int(5) default '0',
  `YC` int(5) default '0',
  `RC` int(5) default '0',
  `MOM` int(5) default '0',
  PRIMARY KEY  (`player_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;

Open in new window

0
Comment
Question by:cataleptic_state
  • 4
  • 3
  • 3
10 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
add a team_player_num field int(2), with a check contraint of allowing values from 1 to 22, and make team_id + team_player_num a unique constraint.

that will ensure that you cannot have values other than 1 to 22 for that field, and with the team_id together ensure you can have max 22 players per team
0
 
LVL 4

Author Comment

by:cataleptic_state
Comment Utility
how will the page interact with this tho?
0
 
LVL 4

Author Comment

by:cataleptic_state
Comment Utility
What I mean is do I just create 1 form, and then do what kind of processing to check?

0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
your insert will need to supply a team_player_num, for the new team member, that is not yet used...
so you could query for all values of the team already used, and not show those, aka use the first value that is not used ...
do you need help coding/doing this query first?
0
 
LVL 4

Author Comment

by:cataleptic_state
Comment Utility
why do i need to have team_player_num, could I not use the player_id?

I think I will need help with the query :'(
I was thinking if the team is selected and the players selected and the total rows = 22 then do not allow insert and make the form disappear and a message come up.
0
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
Comment Utility
>> I was thinking if the team is selected and the players selected and the total rows = 22

Yes, that would be the easiest way.  Your form inserts a single player and a recordset on the same page exists to count the total number of rows for the team_id.  So long as count(player_id) WHERE team_id = x is less than 22, display the form.  As soon as it is not less than 22, do not display the form.

>> I originally thought having 22 boxes on a page with textfields, but thats crazy.

Not as crazy as you might think...You would have the textboxes exist as an array:

<input name="player[]" type="text" />

The user fills out the form and then you would take the array and step through it, inserting each value as a new row in the mysql table.  However, this starts to get you outside of the built-in capabilities of DW unless you buy a different set of extensions.  The first solution is easier to implement but has some issues for the end user (hard to remember who has already been entered unless you take additional steps to display existing player names on the page.
0
 
LVL 4

Author Comment

by:cataleptic_state
Comment Utility
Thank you jason1178 that brilliant. Can you take a look at my other post regarding a results grid, it seems too complicated for me to put together
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
Comment Utility
just my 2 cents: that will work, but is not failsafe... open 2 forms when 21 players are in the team, you have 2 forms to submit another one.
only a constraint on the db level will ensure that the 2nd form will fail to insert...
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
>> that will work, but is not failsafe... open 2 forms when 21 players are in the team, you have 2 forms to submit
>> another one.

Absolutely.  I read the question as a single user who is creating a team and that there should not be multiple users logged in to the same team with creation privileges.  If the latter is indeed the case, then my solution is too simplistic for deployment.
0
 
LVL 70

Expert Comment

by:Jason C. Levine
Comment Utility
>> Can you take a look at my other post regarding a results grid

I saw that one come through and it's fairly tough so I'll need to take a second look at it over the weekend.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now