Ninjakreborn Posted November 28, 2006 Share Posted November 28, 2006 [code]<select name="status" id="status"><option value="none">Please Select One</option><?php// get list of status's$selectstat = "SELECT * FROM oak_status;";$querystat = mysql_query($selectstat);// run query and display themwhile ($rowstat = mysql_fetch_array($querystat)) {echo "<option value=\"{$rowstat[statNo]}\"" . tempvar($rowstat['statNo'], $row['statNo']) . ">{$rowstat[status]}</option>\n"; // display them all}?></select><br />[/code]function[code]<?php// Function Start:// Function Name: tempvar()// Function Parameters: 2// Function Process: This function is used for form's when it come's to making // the form drop down menu's stick. This will allow it to pre-populate drop down menusfunction tempvar($variable, $testvariable) { if ($variable == $testvariable) { echo 'selected="selected"'; }}// end function?>[/code]This is the function I am trying to use to get the drop down menu to 'remember' what was selected from the database. I used this on another project, so I created this function, for now, it's technically working in theory like it's suppose to, but for some wierd reason, it output's it in the wrong area, based on the code at the top, it's outputting the following. I am seeing this inside the html source code.[quote]<label for="status">*Status:</label><br /><select name="status" id="status"><option value="none">Please Select One</option>selected="selected"<option value="7">Complete - Portfolio</option><option value="6">temp status</option><option value="3">NOW!</option><option value="4">Available Spring 2007</option></select><br />[/quote]You see how it's outputing the select area somewhere inf ront of the option, I looked at the programming multiple time's, it should be outputting it inside the <option> like it should be <option value="7" selected="selected">Status Name</option>On whichever one was actually selected.But for some reason this isn't working, and I can't get it to output right. Quote Link to comment Share on other sites More sharing options...
taith Posted November 28, 2006 Share Posted November 28, 2006 [code]function tempvar($variable, $testvariable) { if($variable == $testvariable) return 'selected="selected"';}[/code] Quote Link to comment Share on other sites More sharing options...
Ninjakreborn Posted November 28, 2006 Author Share Posted November 28, 2006 Thanks for the help. Quote Link to comment Share on other sites More sharing options...
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.