Solved

limit mysql insert to 22 players

Posted on 2010-08-17
10
316 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]
ID: 33454772
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
ID: 33454983
how will the page interact with this tho?
0
 
LVL 4

Author Comment

by:cataleptic_state
ID: 33455093
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]
ID: 33455120
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
ID: 33455386
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 500 total points
ID: 33456413
>> 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
ID: 33473314
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]
ID: 33473321
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
ID: 33477169
>> 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
ID: 33487318
>> 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
phpmyadmin 3 32
Site hacked - decoding the PHP? 15 60
WordPress syntax 2 25
How to loop through records  using SELET COUNT 2 14
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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 count occurrences of each item in an array.

911 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

18 Experts available now in Live!

Get 1:1 Help Now