Jump to content

Archived

This topic is now archived and is closed to further replies.

nel

convert from databse to select statement

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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites
thanks for the code..but i still have a problem..

in this code i use while function to call all the data from table_name.
so when running the code it will create many select statement according to my value in select list...
i hope you can help me...thanks a lot

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites

×

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.