Help with Mysql database for Little League | Newbie | | Join Date: Oct 2009 Location: Huntington Beach, California
Posts: 5
| | |
All,
I am learning PHP and MySQL on the fly so if my question shows I don't know what I am doing, it's because I don't. Any help is appreciated.
I have set up a registration database for my kids little league (baseball). I can collect data (name, age, address etc) in the form and post it to the db. I can recall the data edit and repost. Everything works as it is supposed to except one field.
I have a field for parents to volunteer. I use a list select with hard coded choices (coach, asst coach, team mom etc.). It posts fine. But when retrieving for editing how do I get the value of the db field to be the item selected in the list?
thanks
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Help with Mysql database for Little League
Run an UPDATE query on your table with the relevant information. I assume you're POSTing the data. -
UPDATE `tbl_name` SET `col_1` = '$col_1' WHERE `userid` = $userid;
-
Obviously you need to set the values of $col_1 and $userid, and also change the tbl_name and col_1 identifiers.
| | Newbie | | Join Date: Oct 2009 Location: Huntington Beach, California
Posts: 5
| | | re: Help with Mysql database for Little League
I was not clear.
Original posting and updating works great. My problem is populating the form when editing. All fields show up correct except one.
The field is filled by use of a list box. When the record updates it correctly fills the field with the selected value of the list box. My question is when I retrieve that data how do I get the list box to be set on the value of the field?
If the person has previously volunteered for coach when the information comes back I want the select list to show 'coach' not the default.
Sorry if I don't make sense I really appreciate the help.
here is the code: - <tr>
-
<td colspan="5"><div align="center"><strong>PLEASE REVIEW AND UPDATE YOUR INFORMATION</strong></div></td>
-
</tr>
-
<tr>
-
<td width="113"><div align="right">Street - City - Zip:</div></td>
-
<td width="212"><input name="xaddr" type="text" value="<?php echo $address;?>" id="xaddr" size="35" maxlength="35"></td>
-
<td width="90"><input name="xcity" type="text" value="<?php echo $city;?>" id="xcity" size="15" maxlength="15"> </td>
-
<td width="81"><input name="xzip" type="text" value="<?php echo $zip;?>" id="xzip" size="5" maxlength="5"></td>
-
<td width="69"> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Parents/Guardians:</div></td>
-
<td><input name="xp1first" type="text" value="<?php echo $mfirst;?>" id="xp1first" size="15" maxlength="15">
-
<input name="xp1last" type="text" value="<?php echo $mlast;?>" id="xp1last" size="15" maxlength="15"></td>
-
<td colspan="3"><input name="xp2first" type="text" value="<?php echo $dfirst;?>" id="xp2first" size="15" maxlength="15">
-
<input name="xp2last" type="text" value="<?php echo $dlast;?>" id="xp2last" size="15" maxlength="15"></td>
-
</tr>
-
<tr>
-
<td><div align="right">Volunteer For?:</div></td>
-
<td><select name="select" id="select">
-
<option value="Manager">Manager</option>
-
<option value="Coach">Coach</option>
-
<option value="Asst. Coach">Asst Coach</option>
-
<option value="Team Mom">Team Mom</option>
-
<option value="Umpire">Umpire</option>
-
<option value="Scorekeeper">Scorekeeper</option>
-
<option value="Snack Bar">Snack Bar</option>
-
<option value="League Official">League Official</option>
-
<option value="Field Maintenance">Field Maintenance</option>
-
<option value="Team Photographer">Team Photographer</option>
-
<option value="Team Computer Rep">Team Computer Rep</option>
-
<option value="Other">Other</option>
-
<option value="None" selected>No thanks</option>
-
</select></td>
-
<td colspan="2"><select name="select2" id="select2">
-
<option value="Manager">Manager</option>
-
<option value="Coach">Coach</option>
-
<option value="Asst. Coach">Asst Coach</option>
-
<option value="Team Mom">Team Mom</option>
-
<option value="Umpire">Umpire</option>
-
<option value="Scorekeeper">Scorekeeper</option>
-
<option value="Snack Bar">Snack Bar</option>
-
<option value="League Official">League Official</option>
-
<option value="Field Maintenance">Field Maintenance</option>
-
<option value="Team Photographer">Team Photographer</option>
-
<option value="Team Computer Rep">Team Computer Rep</option>
-
<option value="Other">Other</option>
-
<option value="None" selected>No thanks</option>
-
</select></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Email 1:</div></td>
-
<td><input name="xemail" type="text" value="<?php echo $email;?>" id="xemail" size="30" maxlength="40"></td>
-
<td colspan="2"><input name="xemail3" type="text" value="<?php echo $email3;?>" id="xemail3" size="30" maxlength="40"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Email 2:</div></td>
-
<td><input name="xemail2" type="text" value="<?php echo $email2;?>" id="xemail2" size="30" maxlength="40"></td>
-
<td colspan="2"><input name="xemail4" type="text" value="<?php echo $email4;?>" id="xemail4" size="30" maxlength="40"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Phones (10digits):</div></td>
-
<td><div align="left">
-
<input name="xhphone" type="text" id="xhphone" value="<?php echo $phone;?>" size="10" maxlength="10">
-
<input name="xphone2" type="text" id="xphone2" value="<?php echo $cphone2;?>" size="10" maxlength="10">
-
</div></td>
-
<td colspan="2"><input name="xphone3" type="text" value="<?php echo $cphone3;?>" id="xphone3" size="10" maxlength="10">
-
<input name="xphone" type="text" value="<?php echo $cphone4;?>" id="xphone" size="10" maxlength="10"></td>
-
<td> </td>
-
</tr>
-
<tr>
-
<td><div align="right">Second Address:</div></td>
-
<td><input name="xaddr2" type="text" value="<?php echo $address2;?>" id="xaddr2" size="35" maxlength="35"></td>
-
<td><input name="xcity2" type="text" value="<?php echo $city2;?>" id="xcity2" size="15" maxlength="15"></td>
-
<td><input name="xzip2" type="text" value="<?php echo $zip2;?>" id="xzip2" size="5" maxlength="5"></td>
-
<td> </td>
-
</tr>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Help with Mysql database for Little League
In that case, I would output the <option>s via a loop, checking each against the result from the database. -
$volunteer_options = array(
-
'Manager' => 'Manager',
-
'Coach' => 'Coach',
-
'Asst' => 'Assistant',
-
....
-
);
-
-
// This value you will have to pull from the database
-
// I will hardcode it here.
-
$volunteer_choice = 'Asst';
-
-
print '<select name="volunteer">';
-
foreach ($volunteer_options as $key => $option) {
-
printf('<option name="%s" %s>%s</option>',
-
$key,
-
($key == $volunteer_choice) ? 'selected="selected"' : '',
-
$option
-
);
-
}
-
print '</select>';
-
Is that what you're after?
Mark.
| | Newbie | | Join Date: Oct 2009 Location: Huntington Beach, California
Posts: 5
| | | re: Help with Mysql database for Little League
Thanks Mark, looking at the code I think that could be the answer. I will give it a try in the morning, your evening (your time stamp appears to be 8 hrs ahead). Thanks again.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Help with Mysql database for Little League Quote:
Originally Posted by CoachDave48 Thanks Mark, looking at the code I think that could be the answer. I will give it a try in the morning, your evening (your time stamp appears to be 8 hrs ahead). Thanks again. Brill. Let us know how you get on.
| | Newbie | | Join Date: Oct 2009 Location: Huntington Beach, California
Posts: 5
| | | re: Help with Mysql database for Little League
Mark,
Your code should create exactly what I am looking for. Unfortunately, I am struggling to make it work. I know it is something I am doing wrong. I researched printf and associative arrays on w3schools.com but I am still failing.
When you have a minute could you look at it.
This is the output I get (notice the first key and assignment operator are not output). The code I am using follows the display. Quote:
'Manager', 'Coach' => 'Coach', 'Asst Coach' => 'Asst Coach', 'Team Mom' => 'Team Mom', 'Umpire' => 'Umpire', 'Scorekeeper' => 'Scorekeeper', 'Snack Bar' => 'Snack Bar', 'League Official' => 'League Official', 'Field Maintenance' => 'Field Maintenance', 'Team Photographer' => 'Team Photographer', 'Team Computer Rep' => 'Team Computer Rep', 'Other' => 'Other', 'None' => 'No Thanks' ); // This value you will have to pull from the database // I will hardcode it here. $volunteer_choice = 'Asst Coach'; print ''; ?>
select.php - <html>
-
<body>
-
<?php
-
-
$volunteer_options=array(
-
'Manager' => 'Manager',
-
'Coach' => 'Coach',
-
'Asst Coach' => 'Asst Coach',
-
'Team Mom' => 'Team Mom',
-
'Umpire' => 'Umpire',
-
'Scorekeeper' => 'Scorekeeper',
-
'Snack Bar' => 'Snack Bar',
-
'League Official' => 'League Official',
-
'Field Maintenance' => 'Field Maintenance',
-
'Team Photographer' => 'Team Photographer',
-
'Team Computer Rep' => 'Team Computer Rep',
-
'Other' => 'Other',
-
'None' => 'No Thanks'
-
);
-
-
// This value you will have to pull from the database
-
// I will hardcode it here.
-
$volunteer_choice = 'Asst Coach';
-
-
print '<select name="volunteer">';
-
foreach ($volunteer_options as $key => $option) {
-
printf('<option name="%s" %s>%s</option>',
-
$key,
-
($key == $volunteer_choice) ? 'selected="selected"' : '',
-
$option
-
);
-
}
-
print '</select>';
-
-
?>
-
</body></html>
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Help with Mysql database for Little League
Hey, Dave.
The problem is the PHP isn't being parsed. Are you saving this file as .php and running it under your server? That is, accessing it as http://localhost/file.php.
Mark.
P.S. Check out the Please Read Before Posting sticky - specifically, the part about [code] tags. Cheers.
| | Newbie | | Join Date: Oct 2009 Location: Huntington Beach, California
Posts: 5
| | | re: Help with Mysql database for Little League
Mark,
Ouch. I told you I didn't know much. Once I moved the file to htdocs everything worked perfect. I cannot thank you enough for being so willing to share your knowledge.
Newbie's rarely contribute, but I did my part. I provided comedy for the day. Anyone following this thread will laugh at the bleeping idiot.
Thanks again.
|  | Moderator | | Join Date: Jun 2007 Location: York, England, with wolves.
Posts: 4,936
| | | re: Help with Mysql database for Little League Quote:
Originally Posted by CoachDave48 Mark,
Ouch. I told you I didn't know much. Once I moved the file to htdocs everything worked perfect. I cannot thank you enough for being so willing to share your knowledge.
Newbie's rarely contribute, but I did my part. I provided comedy for the day. Anyone following this thread will laugh at the bleeping idiot.
Thanks again. I assure you we've all be there :) and no one's laughing at you! :P
Anyway, be sure to come back with any questions you have.
Mark.
|  | Moderator | | Join Date: Aug 2008 Location: Leipzig, Germany
Posts: 3,620
| | | re: Help with Mysql database for Little League Quote:
Originally Posted by CoachDave48 Anyone following this thread will laugh at the bleeping idiot. I can assure you that we've seen worse.
|  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,223 network members.
|