Jump to content

Populating Drop Down Menu


timmle

Recommended Posts

I am currently using open source php shopping cart and moving into learning a bit more on php and mysql but was wondering if anyone can help me with this.

 

In my database i have a prescription_drop table. In there i have a list of fields but i am just concentrating on one for now so i can apply this to the rest of my project.

 

The field is called rsph_drop inside the prescription_Drop table.

 

This only has one column as i just want to output a list of values that are +10.00, +9.75, +9.50, +9.25, +9.00 and so forth.

 

At the moment i have a text input field which writes to the database in a different area, but i want to change this into a drop down field which writes to the database in a different area.

 

So as i understand it, please correct me if i am wrong, i have to build the values in a table in my database, request information from the database to populate that drop down menu, and then with the one chosen input into the database.

 

So i have this so far on the page...

$rsph = tep_db_prepare_input($HTTP_POST_VARS['rsph']);

 

$sql_data_array = array('customers_rsph' => $rsph,

<td class="main"><?php echo ENTRY_CUSTOMER_RSPH; ?></td>

                <td class="main"><?php echo tep_draw_input_field('rsph', '','maxlength="6"' . 'style="width: 50"') . ' ' . (tep_not_null(ENTRY_RSPH_TEXT) ? '<span class="inputRequirement">' . ENTRY_RSPH_TEXT . '</span>': ''); ?></td>

 

 

This is already part of a larger form with other input fields and such so the form part isn't necessary.

 

the tep_draw_input_field is how this open source software draws a open text field and to put in a drop down menu it is tep_draw_pull_down. I don't mind changing this for generic php commands.

 

What i really need to know is how take the information from the rsph_drop fields in the prescription_drop table to populate a drop down menu. And then allow this information to enter into the 'rsph' field in the 'customers' table

 

 

Thankyou.

 

 

Link to comment
https://forums.phpfreaks.com/topic/176841-populating-drop-down-menu/
Share on other sites

It is difficult to tell you how to accomplish this without knowing how the tep_draw_pull_down() function operates. What are the parameters for that function and what do they do? For example, how do you pass it the values?

 

I would suspect it takes an array for the values (and possibly the labels). So, you can either create a hard-coded list or generate the list from a database. If the list will never (or rarely) change, then a hard-coded list is the easier way to go. if the list will change often, then you can create the list in a database and then create functionality to give an admin the ability to modify the list.

Ok, a little googling came up with the function tep_draw_pull_down_menu for the OsCommers application. The parameters are:

 

tep_draw_pull_down_menu($name, $values, $default = '', $parameters = '', $required = false)

 

And $values appears to need to be a multi-dimensional array in the format

array (
    [0] => array (
        ['id'] => '1',
        ['text'] => 'Value 1'
    ),
    [1] => array (
        ['id'] => '2',
        ['text'] => 'Value 2'
    )
)

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.