rbragg Posted March 14, 2007 Share Posted March 14, 2007 Say I have a droplist (drop11) with 2 sticky options (open & closed): <select name="drop11" id="11" class="style1"> <option value="open" <?php if (isset($_SESSION['drop11']) && $_SESSION['drop11'] == open) { echo 'selected="selected"';} ?> >open <option value="closed" <?php if (isset($_SESSION['drop11']) && $_SESSION['drop11'] == closed) { echo 'selected="selected"';} ?> >closed </select> I have a column in my db named Lot11 with the value of either "open" or "closed". I want to also have the above droplist to display the contents of Lot11 upon page load. How could I do that? Thanks in advance! Quote Link to comment Share on other sites More sharing options...
rbragg Posted March 15, 2007 Author Share Posted March 15, 2007 I assume I would need something like: <?php $query_getStatus = mysql_query("SELECT * FROM db") or die(mysql_error()); while($getStatus = mysql_fetch_array( $query_getStatus )) { ?> <select name="drop11" id="11" class="style1"> <option value='<?php echo $getStatus['Lot11'];?>' <?php if (isset($_SESSION['drop11']) && $_SESSION['drop11'] == open) { echo 'selected="selected"';} ?> >open </select> <?php } mysql_close; ?> But since there is an option of 2 values (open or closed), I don't know how to go about this. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 it's more like this: <?php $sql = "SELECT Lot11 FROM your_table"; $query = mysql_query($sql); echo "<select name=\"drop11\" id=\"11\" class=\"style1\">\n"; while($row = mysql_fetch_array($query)){ echo "<option value=\"{$row['Lot11']}\"". (($_POST['drop11'] == $row['drop11']) ? (" SELECTED") : ("")) .">\n"; } echo "</select>\n"; ?> get the idea? Quote Link to comment Share on other sites More sharing options...
rbragg Posted March 15, 2007 Author Share Posted March 15, 2007 Ah ha ... I see. Thanks for replying. So, for the sql statement, what if I wanted to select from multiple columns ... not just Lot11? Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 this will select every column in the specified table: $sql = "SELECT * FROM your_table"; Quote Link to comment Share on other sites More sharing options...
rbragg Posted March 15, 2007 Author Share Posted March 15, 2007 I have: <?php include 'db_connect.php'; # connect to the db $query_getStatus = mysql_query("SELECT * FROM park_lots") or die(mysql_error()); ?> <?php echo " <select name='drop11' id='11' class='style1'> "; while($get_status = mysql_fetch_array( $query_getStatus )) { echo "<option value=\"{$get_status['Lot11']}\"". (($_SESSION['drop11'] == $get_status['drop11']) ? (" SELECTED") : ("")) .">\n"; } echo "</select>"; ?> My droplist is empty. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 your droplist isn't empty... you just haven't printed a description for your option tags. partially my fault. i guess i forgot =\ echo "<option value=\"{$get_status['Lot11']}\"". (($_SESSION['drop11'] == $get_status['drop11']) ? (" SELECTED") : ("")) .">print something here\n"; Quote Link to comment Share on other sites More sharing options...
rbragg Posted March 15, 2007 Author Share Posted March 15, 2007 I wanted the droplist to display the description for the options on its own. So, if "closed" is stored in the db, the droplist should be defaulted to "closed" with the option to change to open. Hope I'm making sense. Quote Link to comment Share on other sites More sharing options...
boo_lolly Posted March 15, 2007 Share Posted March 15, 2007 i've been confused this whole time as to what you want to do. <select name="drop11" id="11" class="style1"> <option value="open"<?php ((isset($_SESSION['drop11']) && $_SESSION['drop11'] == "open") ? (" SELECTED") : ("")); ?>>open <option value="closed"<?php ((isset($_SESSION['drop11']) && $_SESSION['drop11'] == "closed") ? (" SELECTED") : ("")); ?>>closed </select> i'm pretty sure that's what you want. Quote Link to comment Share on other sites More sharing options...
rbragg Posted March 15, 2007 Author Share Posted March 15, 2007 Well, that's exactly what I had at the beginning. That will give me sticky values in case the user presses submit, fails validation and returns to the page. This is what I want along with: Upon the first visit to the page, I want the user to see, as the default value, the value that is currently stored in the database. That value will either be "open" or "closed". So, if in the database a lot is closed, the droplist will say "closed" but they can use the drop-down to see "open" if they wish. 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.