Solved

pull data from DB to a drop down list ..

Posted on 2002-05-09
7
196 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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 …

746 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

13 Experts available now in Live!

Get 1:1 Help Now