Solved

pull data from DB to a drop down list ..

Posted on 2002-05-09
7
198 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
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses how to create an extensible mechanism for linked drop downs.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

828 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