Reputation: 301
I want to add in drop down list first option manual and after all from my "game table".
In my code everything works fine but my manual option "select" repeat every time after the result from game table.
Here is my code
<!DOCTYPE HTML>
<html>
<head>
<title>Update Result</title>
</head>
<body>
<?php
//Connect to Database Server
include 'secure.php';
//Select a Table from Database
$query = "SELECT * FROM game";
//Get Result from Table (all)
$result = mysqli_query($connect,$query);
?>
<!-- Head Line -->
<h3> Update Result</h3>
<!-- Create Result Form -->
<form action="rsave.php" method="post">
<label>Date:</label><input type="date" name="ResultDate" tabindex="1" min="1899-12-31" max="2100-12-31" title="Please Enter Correct Date" required ><br>
<!--Select Start with PHP-->
<label>Game:</label><select id="Select1" name="ResultName" tabindex="2" title="Select a GameName" required >
<?php
// PHP Again
while ($line = mysqli_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="">SELECT</option>
<option value="<?php echo $line['GameID'];?>"><?php echo $line['name'];?></option>
<?php
}
?>
</select><br>
<!--Select End with PHP-->
<label>ReNO:</label><input type="number" name="ResultNo" min="0" max="100" tabindex="3" pattern="[0-9]{2,3}" title="Add a Number Between 0 to 100"required ><br>
<input type="submit" value="Update" tabindex="4">
<input type="reset" value="Reset" tabindex="5"><br>
</form>
</body>
</html>
Upvotes: 0
Views: 1337
Reputation: 888
pull this line:
<option value="">SELECT</option>
above your while loop, like this:
<label>Game:</label>
<select id="Select1" name="ResultName" tabindex="2" title="Select a GameName" required >
<option value="">SELECT</option>
<?php
// PHP Again
while ($line = mysqli_fetch_array($result, MYSQL_ASSOC)) {
?>
<option value="<?php echo $line['GameID'];?>"><?php echo $line['name'];?></option>
<?php
....
Upvotes: 1