473,323 Members | 1,551 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

retrieve data from mysql database to display in a dropdown box with php

1
Hello everybody,
I am quite beginner as a software professional in php & mysql. I want to know how I can fetch data from mysql database to show in a form's drop down box with php coding. I request all to help me in this regard.
Sincerely,
Vireshwar,
Chennai,India
May 22 '07 #1
1 6756
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <?php
  5.  
  6. $con=mysql_connect("localhost","root","") 
  7. or die('Could not connect: ' . mysql_error());
  8.  
  9.  
  10. mysql_select_db("my_db", $con);
  11.  
  12. $result = mysql_query("SELECT username FROM users")
  13. or die("Invalid Query: " .mysql_query());
  14.  
  15. echo '<label>Select username:</label>';
  16. echo '<select id="username"  name="username">';
  17. echo '<option value="">Select</option>';
  18.  
  19. while ($row = mysql_fetch_assoc($result))
  20. {
  21. $va = $row['username'];
  22. echo "<option value='$va'>$va</option>";
  23. }
  24. echo '</select>';
  25.  
  26. mysql_close($con);
  27. ?>
  28.  
  29. </body>
  30. </html>
  31.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

hope it would help you.
May 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
3
by: Richard Carpenter | last post by:
I understand how to use a dropdown list control to display the associated description value for a foreign key in a parent rather than the key itself, but I don't like having to disable the control...
4
by: assgar | last post by:
Hi I am stuck on a problem. I use 3 scripts(form, function and process). Development on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. The form displays...
13
by: kev | last post by:
Hi all, I have created a database for equipments. I have a form to register the equipment meaning filling in all the particulars (ID, serial, type, location etc). I have two buttons at the end...
3
by: JM | last post by:
Before storing information from a form in database I perform follwing operations on it : $path = mysql_real_escape_string(strip_tags(trim(urldecode($_POST)))); $summary =...
2
by: mukeshrasm | last post by:
hello i want to display the subjects on the same page based on class selected by user. i am using dropdown for classes. so when user will select a particular class then it will display subjects in...
8
by: Wingot | last post by:
Hey, I have a program I am trying to write using Visual C#, SQL Server 2005/2008, and Visual Studio 2008, and one part of it includes a Schema called Client. Inside this schema, three tables...
2
by: zek2005 | last post by:
Hi! I have a value loaded in a database as following: &lt;p&gt;&lt;strong&gt;test&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;test 2&lt;/ strong&gt;&lt;em&gt;&lt;strong&gt;questions&lt;img alt=&quot;&quot;...
12
lifeisgreat20009
by: lifeisgreat20009 | last post by:
I am a newbie to Struts and JSP...I have been working on the code below for 5 hours now..I googled a lot but couldn't get much help so finally I am here.. Hoping of getting my problem solved. Please...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.