Jump to content


Photo

convert from databse to select statement


  • Please log in to reply
5 replies to this topic

#1 nel

nel
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 August 2006 - 10:27 AM

i have some data for example :

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

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 31 August 2006 - 11:28 AM

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.

//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>';

Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 nel

nel
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 August 2006 - 12:46 PM

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

#4 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 31 August 2006 - 12:53 PM

not if you put the <select> and </select> outside of the while loop.
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#5 nel

nel
  • Members
  • PipPip
  • Member
  • 19 posts

Posted 31 August 2006 - 01:07 PM

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.



#6 Yesideez

Yesideez
  • Members
  • PipPipPip
  • Advanced Member
  • 2,334 posts
  • LocationDevon, UK

Posted 31 August 2006 - 01:15 PM

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:
SELECT * FROM table ORDER BY `value` ASC

Not a pro just an enthusiast :)

if (empty($coffee)) {$coffee=new coffee();}

Please surround any code using the CODE tags - I rarely look at anything without them




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users