Issue
while ($row = mysqli_fetch_array($result)){
$move = '
<select type = text name="mover">
<option>select something</option>
'".while ($dbrow = mysqli_fetch_array($result)){
echo "<option value='".$dbrow['deptname']."'>".$dbrow['deptname']."</option>";}."'
</select>';
echo '<tr><td>'.$row['name'].'</td><td>'.$move.'</td></tr>';}
I am trying to display dropdown list inside the table. However whenever I apply while(...) codes, it displays an error.
shouldn't HTML + '".PHP."' + HTML be the correct way?
Solution
Generate the select menu before entering the main loop that builds the table and then rewind the recordset so that the main loop can begin
<?php
$html='<select name="mover">
<option selected disabled hidden>Please select something';
while( $row = mysqli_fetch_array( $result ) ){
$html.=sprintf('<option>%s',$row['deptname'] );
}
$html.='</select>';
$result->data_seek(0);
?>
Then build the table.
<table>
<?php
while( $row = mysqli_fetch_array( $result ) ){
printf('<tr><td>%1$s</td><td>%2$s</td></tr>',$row['deptname'],$html);
}
?>
</table>
Answered By - Professor Abronsius
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.