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
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.

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.