Link to home
Start Free TrialLog in
Avatar of suelow
suelow

asked on

pull data from DB to a drop down list ..

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
Avatar of lokeshv
lokeshv

after that

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

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

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


Hope this helps...

LK
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>
ASKER CERTIFIED SOLUTION
Avatar of Rajko
Rajko

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
strange....

btw wat did u find in his code ?

Lk
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.
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