Jump to content

Drop down menu


drax

Recommended Posts

Hi there,

 

I was hoping for a little help a with project please.

 

In a form I have a drop down menu that selects records in database and displays them as options to the user. The table that is searches has only 2 fields (ID & name). On the Drop down i have it so the user sees the name of the record and not the ID of it, but at the moment it UPDATES only the ID and not the name.

 

How do i make it so both the ID and Name are UPDATED from using just the drop down???????

 

If anybody could help that would be ace!

 

Thanks

 

Link to comment
Share on other sites

Hi,

yes sorry, it is a form and in it is 1 drop down menu and a submit button (onclick the record is INSERTED).

 

The drop down menu displays records that have been searched from a table in my database (ID and Name). in the option it displays the Name to the user but INSERTS the ID.

 

I need it to not only INSERT the ID value from the drop down into the ID field of that table BUT to ALSO INSERT the Name. The Drop Down has both of those details as it displays the name and INSERTS the ID.

 

Heres the code of the INSERT:

 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO table (bID, aID, ID, name) VALUES (%s, %s, %s, %s)",
                       GetSQLValueString($_POST['ID'], "int"),
                       GetSQLValueString($_POST['aID'], "int"),
                       GetSQLValueString($_POST['select'], "int"),

 

I wanted to try to add the Name here in the INSERT, I tried linking it to select, text. I also tried linking to a hidden field <? echo $row_list['Name']?> to it....

 

 

Heres the code for the drop down:

 

[code]<select name="select">
    <?php
do {  
?>
    <option value="<?php echo $row_list['ID']?>"><?php echo $row_list['Name']?></option>
    <?php
} while ($row_list = mysql_fetch_assoc($list));
  $rows = mysql_num_rows($list);
  if($rows > 0) {
      mysql_data_seek($list, 0);
  $row_list = mysql_fetch_assoc($list);
  }

[/code]

 

Please help me

 

Thanks

Link to comment
Share on other sites

If you really want it, you can query the same table that you originally made the drop down from:

INSERT INTO table (ID, Name) VALUES ($_POST['ID'], (SELECT Name FROM othertable WHERE ID = $_POST['ID']))

 

But like BlueSkyIS said, it is redundant to store the same data like. If you wanted to do it from the form you would have to make some hidden values that are changed before submision with javascript. Something like:

<input type=hidden name="name">
<input type=submit onclick="name.value=select.value;formname.submit()">

Link to comment
Share on other sites

Hi,

 

Thanks for all your help.

But then how would i be able to select the appropriate names to display back to the user because it would need to search one table to find all the IDs of one (url parameter) and then with all IDs known that would then need to be queried against the original table that has both ID and name.

 

How would you do that??

 

Thanks

 

Link to comment
Share on other sites

Hi,

 

thanks very much for replying,

 

I'm a bit of a newbie at this, bit confused about the $user_critera bit where else would that need to be used????

 

I'm using 3 tables here Main ID, experience (ID & Name) and actual_experience (holds ID of both Main and experience).

 

How would i implement this???

 

Thanks

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.