?
Solved

pull data from DB to a drop down list ..

Posted on 2002-05-09
7
Medium Priority
?
201 Views
Last Modified: 2011-04-14
Hi,

I'm a ASP programmer.. and I"m very new in php.
May I know how to pull data from a table and output it in a drop down list ??

<select name=glass>
<?php
   $db = mysql_connect("localhost", "root", "");
   mysql_select_db("Optics",$db);
   $result=mysql_query("select glass from Glass");

// from here how to continue ??

?>
</select>


I found that php got no EOF() function .. how to use loop to display the data in a drop down list ?? Please advice..

Thanks
0
Comment
Question by:suelow
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 4

Expert Comment

by:lokeshv
ID: 6998507
after that

<?whiler($row=mysql_fetch_array($qid)){?>

<option value="<?=$row[field1]?>"><?=$row[field2]?></option>

<?}?>
</select> //end of ur select


Hope this helps...

LK
0
 
LVL 32

Expert Comment

by:Batalf
ID: 6998601
Adjust lokeshv code to your like this:

<select name=glass>
<?php
  $db = mysql_connect("localhost", "root", "");
  mysql_select_db("Optics",$db);
  $result=mysql_query("select glass from Glass");
  // Data found in the resultset?
  if($info = mysql_fetch_array($result))
  {
     // Loop through each row in the resultset.
     do
     {
           echo "<option value=\"".$info["glass"]."\">".$info["glass"]."</option>\n";

     }while($info = mysql_fetch_array($result));
  }
?>
</select>
0
 
LVL 1

Accepted Solution

by:
Rajko earned 200 total points
ID: 6998612
<html>
<head>
<title></title>
</head>
<body>
<?php
$host = "localhost";
$user = "root";
$pass = "0";
$dbase = "your_database";
$db = mysql_connect($host, $user, $pass) or die ("verbindung fehlgeschlagen");
      mysql_select_db($dbase, $db) or die ("verbindung zur datenbank fehlgeschlagen");

$sql = "select * from test_table";
$result = mysql_query($sql,$db);
?>
<select name="list">
<?php
if($result){
 while($row = mysql_fetch_array($result)){
  echo "<option value=\"".$row['column_name']."\">".$row['column_name']."</option>\n";
 }
}
?>
</select>
</body>
</html>

it's you write the tag attruibute in dopple qoutes und you define your php as <?php ?> not <? ?>
xml use the same tag! <?xml ?>. the parser can't know whta language is mean, xml or php.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 32

Expert Comment

by:Batalf
ID: 6999152
Rajko: You should NOT propose answer on something that does the same as the comment posted previously. Now, you have locked the question!

Why not just post comments and let the user asking the question evaluates them and then accept the one he likes best as an answer???

Batalf
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 7007425
strange....

btw wat did u find in his code ?

Lk
0
 
LVL 32

Expert Comment

by:Batalf
ID: 7007856
I agree with you lokeshv. The only result of this question is as far as I can see that Rajko could continue his annoying habit of proposing answers on question whene he shouldn't.
0
 
LVL 4

Expert Comment

by:lokeshv
ID: 7007869
Yeah Baltaf yor are right.

this is really annoying somone comes and directly post the answer when already two comments have been posted into the quesation and his answer is nothing diferent..


Lk
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question