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
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
Link to comment
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
Link to comment
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.

Link to comment
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]
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.