Hi, i want to select with php the category of a record that i want to display when i update it. Like this this is my PHP code: <select name="cid" class="input" style="padding:2px;"> <option value="<?php echo $row['cid']; ?>" selected> <?php echo $row['cid'];?></option> <?php $result2 = mysql_query("SELECT * FROM menu ORDER BY id"); while($row2 = mysql_fetch_assoc($result2)) { ?> <option value="<?php echo $row2['id'];?>"> <?php echo $row2['id'].". ".$row2['title'];?></option> <?php } ?></select> PHP: i hope that you can help me. thanks in advance
I'm a little unsure as to what you are asking for - do you want the information in the whole form to update when you change selection? If so, you can't do that with PHP alone - then you'd need to look to javascript. The selected record will, as far as I can see, affect which row in the database would be updated with the values entered in the form, if used as is. But I think you mean that you want the form to update the displayed information based on the select box? If there is something else you want to do, please tell us in more detail.
try this <select name="cid" class="input" style="padding:2px;"> <?php $result2 = mysql_query("SELECT * FROM menu ORDER BY id"); while($row2 = mysql_fetch_assoc($result2)) { $selected = ($row['cid'] != $row2['id']) ? ' selected' : ''; ?> <option value="<?php echo $row2['id'];?>" <?php echo $selected; ?>> <?php echo $row2['id'].". ".$row2['title'];?></option> <?php } ?></select> Code (markup):