jemmm 0 Posted December 10, 2011 Report Share Posted December 10, 2011 Hi there, I have an edit details page on my website (php with a mysql database). It contains text boxes which display the information which the user has submitted at an earlier date. If they edit the information in the textbox and click on the submit button, it will update in the database. These work fine without any problems. I now want to add a pulldown menu which will work in the same way by displaying the information that the user saved on a previous visit (but obviously they can choose other options and click submit to save). My problem is that I am only able to show either the first or the list item on the list when the page opens and not the item that the user has selected on the previous visit. Any help would be appreciated. echo '<tr><td>Change Timeframe</td><td> <select name="checklist_timeframe_id">'; //query that will display all the options that the user can select $cq = "SELECT * FROM checklist_timeframe"; $cr=mysqli_query($dbc,$cq) or die(mysqli_error($dbc)." Q=".$cq); //if the query runs successfully if ($cr) { while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['checklist_timeframe_id']; if ($info['checklist_timeframe_id'] ==$ca['checklist_timeframe_id']) { echo '"selected="selected'; } echo '">' . $ca['checklist_timeframe'] . '</option>'; mysqli_free_result($cr);//free up resources } } else { echo '</select>We apologise there seems to be a problem with this data'; } //echo '</select>'; Quote Link to post Share on other sites
David L 4 Posted December 11, 2011 Report Share Posted December 11, 2011 Try while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['checklist_timeframe_id'] . '"'; if ($info['checklist_timeframe_id'] ==$ca['checklist_timeframe_id']) { echo ' "selected="selected"'; } echo '>' . $ca['checklist_timeframe'] . '</option>'; mysqli_free_result($cr);//free up resources } 1 Quote Link to post Share on other sites
David L 4 Posted December 11, 2011 Report Share Posted December 11, 2011 Woops, typo, try: while ($ca = mysqli_fetch_array($cr, MYSQLI_ASSOC)) { echo '<option value="' . $ca['checklist_timeframe_id'] . '"'; if ($info['checklist_timeframe_id'] == $ca['checklist_timeframe_id']) { echo ' selected="selected"'; } echo '>' . $ca['checklist_timeframe'] . '</option>'; mysqli_free_result($cr);//free up resources } 2 Quote Link to post Share on other sites
jemmm 0 Posted December 20, 2011 Author Report Share Posted December 20, 2011 Thanks for your help. It worked but only when I realised I had closed off the main while loop before this section of code so it couldn't read the $info['checklist_timeframe_id'] so I moved the closing curly bracket to the end of the above section of code and it worked (I had it placed before the above section). A silly mistake on my part! thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.