Jump to content

Select drop down lists


thomashw

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/85737-select-drop-down-lists/
Share on other sites

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.

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>

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.

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.