Storing Drop Down Options

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sockpuppet
Forum Newbie
Posts: 22
Joined: Tue Jan 18, 2011 8:38 am

Storing Drop Down Options

Post by sockpuppet »

Anyone got a nifty way to store drop down box variables.

I'm thinking that either the usual one mysql table per drop down (lots of tables!) or doing something like:

id,
drop_down_name, // the id of the drop downn
drop_down_value, // the value returned by the input
drop_down_display, // the text to display
drop_down_default, // the default selected option

and just calling the options as I need them into an array.

Anyone else found a good way of dealing with drop downs and storing the variables for them?
raj23
Forum Newbie
Posts: 3
Joined: Tue Jan 25, 2011 6:30 am

Re: Storing Drop Down Options

Post by raj23 »

Hi bro,
You can use the following coding it'll be useful for you.
<?php
if ($_SERVER['REQUEST_METHOD']!= 'POST')

{
$rowsPerPage = $_post['choice'];

echo

'<form name="choice" method="post" action="post">

<select name="choice">

<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>

</select>

<input type="submit" name="choice" value="submit"/>

</form>';}?>
Drupal web developer
sockpuppet
Forum Newbie
Posts: 22
Joined: Tue Jan 18, 2011 8:38 am

Re: Storing Drop Down Options

Post by sockpuppet »

I think you've got the wrong end of the stick :(

I'm after how to store the values sensibly in a database. A lot of the drop downs I use are dynamic so storing them in a database is the only way, just wondering what approach people favoured the multi_tables approach or the single table with an extra variable approach.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Storing Drop Down Options

Post by AbraCadaver »

sockpuppet wrote:I think you've got the wrong end of the stick :(

I'm after how to store the values sensibly in a database. A lot of the drop downs I use are dynamic so storing them in a database is the only way, just wondering what approach people favoured the multi_tables approach or the single table with an extra variable approach.
It depends on how many and if they are all related. What do these dropdowns represent. Normally I use 1 table for each dropdown to hold the possible values, but the actual selected data that the user submits will be held in some other table depending on the data.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
sockpuppet
Forum Newbie
Posts: 22
Joined: Tue Jan 18, 2011 8:38 am

Re: Storing Drop Down Options

Post by sockpuppet »

Nothing much just

UK => United Kingdom
US => USA

Style data. Just thinking it was a neater way than having one table per drop down.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Storing Drop Down Options

Post by AbraCadaver »

sockpuppet wrote:Nothing much just

UK => United Kingdom
US => USA

Style data. Just thinking it was a neater way than having one table per drop down.
I think your approach sounds good. Try it out and see how you like it.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply