Jump to content

Drop Down Menu Displaying 1 less option than what is in the table


abie

Recommended Posts

So I have a form and I'm trying to populate the drop down menu with players that match certain specifications.  I've got the code to work (partially) but the drop down menu is always 1 record short of what is in the database. (If there are 4 rows matching the criteria, 3 are shown in the drop down list. 

 

When I isolate the code, the drop down menu displays all the records, so I'm at a loss here. Here is the code: (The part that calls for the records is preceded by a bunch of ************'s

 

<?
include("includes/boxhead.inc");
include("includes/config.php");
include("includes/opendb.php");

$user = $_GET['username'];
// echo $capt_name;
// echo "<p>";

[color=red]$query = "SELECT *
FROM players
INNER JOIN login
ON players.team_id=login.id where login.username = '$user'";

$result=mysql_query($query);

$row = mysql_fetch_row($result);
[/color]$id = $row['0'];


echo <<<EOT

<script language="JavaScript">
<!--
var getSelected = function(dropdownObject) {
    // this is a little function that returns he selected value of a dropdown
    return dropdownObject[dropdownObject.selectedIndex].getAttribute("value");
}; // end, testd in IE7 and FF3.06

var changeForm = function(whatDropdown) {
    // defines the form toggler based upon the dropdown element passed
    var form1 = document.getElementById("form1"), form2 = document.getElementById("form2"), form3 = document.getElementById("form3"), form4 = document.getElementById("form4");

    if (getSelected(whatDropdown) == "form1") {
        form1.style.display = "block";
        form2.style.display = "none";
form3.style.display = "none";
form4.style.display = "none";
    }
    else
    {
    if (getSelected(whatDropdown) == "form2")  {
        form1.style.display = "none";
        form2.style.display = "block";
form3.style.display = "none";
form4.style.display = "none";
    }

    else
    {
    if (getSelected(whatDropdown) == "form3") {
    	form1.style.display = "none";
form2.style.display = "none";
form3.style.display = "block";
form4.style.display = "none";
}
    else
{
    if (getSelected(whatDropdown) == "form4") {
        form1.style.display = "none";
form2.style.display = "none";
form3.style.display = "none";
form4.style.display = "block";
        }
}
}
}
};
//--></script>


Score submission has been temporarily disabled<p>
<form>
Select your league and stat type:    <select name="selectList" onChange="changeForm(this)"> <!-- notice i pass on 'this' which self references the select object -->
        <option>Choose</option>
	<option value="form1">APA 9 Ball</option>
        <option value="form2">TAP 8 Ball</option>
	<option value="form3">APA 8 Ball</option>
	<option value="form4">TAP 9 Ball</option>
    </select>
</form>

<div id="form1" style="display: none;">
<p>Submit your stats here!<p>
<FORM action="submit_stats.php" method="post">
<INPUT type="hidden" name="user" value={$username} readonly="READONLY"/>
<p>
<label for="date">Date Played:</label><INPUT type="text" name="date" id="date"/><br />
EOT;
echo "<label for='name'>Players Name:</label><select name='player' id='name'>";

//*****************************************
echo '<option value="">Select</option>';

while ($row = mysql_fetch_assoc($result)) {
$va = $row['player'];
echo "<option value='$va'>$va</option>";
}
echo <<<EOT
</select><br />
<label for="p_score">Players Score:</label> <INPUT id="p_score" type="text" name="player_score" /><br />
<label for="level">Players Level:</label> <INPUT id="level" type="text" name="level" /><br />
<label for="inn">Innings:</label> <INPUT id="inn" type="text" name="innings" /><br />
<label for="dead">Dead Balls:</label> <INPUT id="dead" type="text" name="dead_balls" /><br />
<label for="opp_score">Opponents Score: </label><INPUT id="opp_score" type="text" name="opp_score" /><br />
<label for="opp_level">Opponents Level:</label> <INPUT id="opp_level" type="text" name="opp_level" /><br />
<label for="break">Break & Run:</label> <INPUT id="break" type="text" name="run" /><br />
<label for="snap">9 on the Snap:</label> <INPUT id="snap"type="text" name="snap" /><br />
<label for="def">Defensive Shots:</label> <INPUT id="def" type="text" name="defensive" /><br />
Total Games: (Both scores + Dead Balls/10) <INPUT type="text" name="total_games" /><br />
Game Result: (W or L) <select name="result">
<option>Result</option>
<option value="W">Win</option><option value="L">Loss</option></select><br />
<input type="hidden" name="team_id" value="$id">
<input type="hidden" name="stat_type" value="APA 9 Ball">
<INPUT type="submit" value="Submit my Score"> or <a href="members.php">Cancel</a><p>
</FORM>
<p></div>
<div id="form2" style="display: none;">
<p>Submit your stats here!<p>
<FORM action="#" method="post">
<INPUT type="hidden" name="user" value={$username} readonly="READONLY"/>
<p>
<label for="date">Date Played:</label> <INPUT id="date" type="text" name="date" /><br />

EOT;
echo "<label for='name'>Players Name:</label><select name='p_name' id='name'>";
//get the content
while($r=mysql_fetch_array($result))
{
$member=$r['player'];

//display the row
echo "<option value=\"$member\">$member</option>";

};
echo <<<EOT
</select><br />


<label for="won">Games Won:</label> <INPUT id="won" type="text" name="g_won" /><br />

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.