thomashw Posted January 12, 2008 Share Posted January 12, 2008 Is it possible to name a select box dynamically, such as: <select name=\"$row[feature_item_name]\"... and then have the form submit to a page which has this code: if(isset($_POST['$row[feature_item_name]'])) { $name = $_POST['$row[feature_item_name]']; } Or is there a better way to do it? What I want to be able to do is have the select boxes dynamically generated from my database, and then have whatever the user selects placed in my database. The problem with naming the select an actual name is I may have one, or many of them on my site. So if they had the same name I wouldn't be able to get all the values. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted January 12, 2008 Share Posted January 12, 2008 Uh what would be the purpose of naming it like that? Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 12, 2008 Author Share Posted January 12, 2008 The dropdown lists are dynamically generated meaning there may be one, two, or five. I need a way to be able to save their values to show on the next few pages the user goes to. I don't know how to do this since I can't have all the select boxes have the same name. I'm using sessions and have a "temp" table on my database which uses the session id to recall the information later on. I've been able to save other things to this table which only have one instance, but with these select boxes I can't figure out how to do it. If you have any ideas, I'd definitely be open to them. Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Share Posted January 12, 2008 Here is an example of one I have that is created dynamically using data from a database: Item Type: <br> <select name="ItemType"/> <?php //Establish a connection to the Database $conn = mysql_connect($Host,$Username,$Password) or die(mysql_error()); //Select the MySQL database $db = mysql_select_db($Dbname, $conn); $sql = "SELECT ItemType FROM ItemType ORDER BY ItemType"; $rs = mysql_query($sql, $conn) or die(mysql_error()); while($row = mysql_fetch_array($rs)) { echo"<option value='{$row['ItemType']}'>{$row['ItemType']}</option>"; } mysql_close($conn); ?> </select> Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 12, 2008 Author Share Posted January 12, 2008 I mean the select boxes are dynamically generated, not the options. So I could have four select boxes, each with multiple options. If I named each select box "itemtype" I would only be able to show the value of the last select box on the next page, wouldn't I? I need some way to show the values of multiple select boxes on the next page. Quote Link to comment Share on other sites More sharing options...
psychowolvesbane Posted January 12, 2008 Share Posted January 12, 2008 You may get away with calling all of the item_name if you made it an array like item_name[] but I don't really know how to retrieve anything from it. If you were only dealing with list selections with definite names then using the $_POST['select_list_name'] will retrieve the value that was selected no problem, you'd just need to work out a way to do this for multiple list boxes with varying names. Quote Link to comment Share on other sites More sharing options...
thomashw Posted January 13, 2008 Author Share Posted January 13, 2008 That works! WOW, I've been trying to do this all day. Now I just need to get each value out of the array, and I forget how. Bah. 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.