Help with table / select box.
Posted: Tue Jan 04, 2011 8:08 am
Hello everyone. I'm working on a website for a youth softball organization, and starting the conversion from straight HTML to PHP / MySQL. I'm trying to make it possible to reschedule rainout games, but I want to do it with select boxes for ease of use. I have most of the code together, but I can't get the select box to populate on subsequent lines...
This is my first code posting, so let's hope I do a decent job...
Right now, the table headings are as follows, and work fine:
Date | Time | Field | Division | Away Color | Away Manager | Home Color | Home Manager.
If the games are rained out, the only thing that will need an update will be the first three columns, as they same teams will still be playing each other. So here's my code.
When I run it, all lines get select boxes, but only the first line's select box has any data in it. Why aren't the rest of the select boxes populating?
It does default to the proper (current) field. This isn't critical, but it's a nice double-check to see the dates / times / fields before they are changed. And that part of the code works, so I don't think I need to pull it out.
I want to use the query to pull the fields as there's a few fields we use rarely, but I still want them to be available for use. Also, if we need to add another field that's not in the list, I can create a page to add a field, and then it's available in the list.
I haven't figured out how I want to do the date and time yet, but I'll get to those in the future. Having a touch of problem displaying AM / PM time, but having it sort properly. There's plenty of examples out there, so I'll get that taken care of soon.
Thanks for any and all time you can spare!
Jef
EDIT: Forgot the PHP tags.
This is my first code posting, so let's hope I do a decent job...
Right now, the table headings are as follows, and work fine:
Date | Time | Field | Division | Away Color | Away Manager | Home Color | Home Manager.
If the games are rained out, the only thing that will need an update will be the first three columns, as they same teams will still be playing each other. So here's my code.
Code: Select all
<?php
$result = mysqli_query($cxn,$schedulequery) #pulls the schedule
or die ("Couldn't execute query.");
$fieldresult = mysqli_query($cxn,$fieldquery) #pulls the list of fields
or die ("Couldn't execute field query.");
echo "<H1>2011 Pigtail Selectable Schedule</H1>\n";
echo "<table border='1' cellpadding='5'>\n";
while($row = mysqli_fetch_assoc($result))
{
extract ($row);
$f_Date = date("F j", strtotime($Date)); #formats the date from YYYY-MM-DD to April 5
echo "<tr>\n
<td>$f_date</td>\n
<td>$Time</td>\n
<td><select>"; #creates select box
##reset ($fieldresult); This didn't work, I tried it in a few locations
while($row2 = mysqli_fetch_assoc($fieldresult)) #pulls fields from the list of different fields
{
extract ($row2);
echo "<option value=\"$Fieldsel\" ";
If ($Field == $Fieldsel) #sets select default to whatever the current field is
#$Field is in Schedule, $Fieldsel is the field select table.
{
echo " selected = 'selected'";
}
echo ">$Fieldsel</option>\n";
}
##tried the reset here too
echo "</select></td>\n #end select box
<td>$Division</td>\n
<td>$AwayColor</td>\n
<td>$AwayManager</td>\n
<td>$HomeColor</td>\n
<td>$HomeManager</td>\n
</tr>\n";
}
##Tried reset here also
echo "</table><BR /><BR />\n";
?>
It does default to the proper (current) field. This isn't critical, but it's a nice double-check to see the dates / times / fields before they are changed. And that part of the code works, so I don't think I need to pull it out.
I want to use the query to pull the fields as there's a few fields we use rarely, but I still want them to be available for use. Also, if we need to add another field that's not in the list, I can create a page to add a field, and then it's available in the list.
I haven't figured out how I want to do the date and time yet, but I'll get to those in the future. Having a touch of problem displaying AM / PM time, but having it sort properly. There's plenty of examples out there, so I'll get that taken care of soon.
Thanks for any and all time you can spare!
Jef
EDIT: Forgot the PHP tags.


