Jump to content

convert from databse to select statement


nel

Recommended Posts

i have some data for example :

                [B]data_name                value        [/B]
                      place                        USA
                      place                        UK
                      place                        RUSIA
                      place                        CHINA
                      place                        JAPAN

so how i can call from database this data into select, radio and check box.

for example:    place:    <select name=place>
                                    <option value=USA>USA</option>
                                    <option value=USA>USA</option>
                                    <option value=USA>USA</option>

and more ....
Link to comment
https://forums.phpfreaks.com/topic/19248-convert-from-databse-to-select-statement/
Share on other sites

can't make out if your wanting to display data from the table into the select box or if your wanting to use the data to be inserted into the database? here is how you would echo the data from the database into a select.

[code]//your connection up here
$query=mysql_query("SELECT * FROM tablename") or die(mysql_error());
echo '<select name=place>';
while ($row=mysql_fetch_array($query)) {
echo "<option value=$row[data_name]>$row[value]</option>"
}
echo '</select>';[/code]

Regards
Liam
i'm not understand yet...

i have 1 question:

i want to insert data using array. i get the data from $_post.when data inserted its showed for example:
                    data_name                value
                      place                        USA
                      place                        UK
                      place                        RUSIA
                      place                        CHINA
                      place                        JAPAN

so i want you to help me, how to insert place and USA in first inserting and next inserting only for value.this because i want to get this data back in select statement.
thanks.

Does it have to be at the beginning? If not you can add it to the array using array_push():

http://uk2.php.net/array_push

If you're adding it into the database then run a SELECT query to pull the data and sort it all into alphabetical order:
[code]SELECT * FROM table ORDER BY `value` ASC[/code]

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.