Solved

pull data from DB to a drop down list ..

Posted on 2002-05-09
7
199 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 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
Industry Leaders: 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone 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

This article discusses four methods for overlaying images in a container on a web page
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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…
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 …

749 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