I am using the following code to update my database from a drop down menu pulling information from another table
<?php
$query = "select id, accountname from reg";
$result = $mysqli->query( $query );
echo '<select id="domain_account" name="domain_account">';
echo '<option value="">';
echo $row['domain_account'];
echo '</option>';
while ($row = $result->fetch_assoc()){
?>
<option value="<?php echo $row['accountname']; ?>"><?php echo $row['accountname']; ?></option>
<?php
}
echo "</select>";
?>
The problem is that if i have 2 or more drop down elements only the top one reads the current record
You'll need to fire another query to populate the next selection box. Or you can save the current query results in a variable and reuse that.
<?php
$query = "select id, accountname from reg";
$result = $mysqli->query( $query );
echo '<select id="domain_account" name="domain_account">';
echo '<option value="">';
echo $row['domain_account'];
echo '</option>';
while ($row = $result->fetch_assoc()){
echo '<option value="'.$row["accountname"].'">'.$row["accountname"].'</option>';
}
echo '</select>';
?>
That should already solve the issue you would have of breaking you while
loop. But your code seems incomplete: where do you get your domain_account
field? Where is your request?
while ($row = $result->fetch_assoc()){
$all_rows[] = $row;
?>
<option value="<?php echo $row['accountname']; ?>"><?php echo $row['accountname']; ?></option>
<?php
}
echo "</select>";
foreach($all_rows as $row) {
//do stuff with $row like echo $row['something'];
}