Solved

pull data from DB to a drop down list ..

Posted on 2002-05-09
7
197 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
  • 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 100 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

919 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now