2 Replies - 10022 Views - Last Post: 15 March 2012 - 12:27 AM Rate Topic: -----

#1 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

how retrieve from database as drop down list?

Posted 14 March 2012 - 11:22 PM

hi ,
i create php code but i wanna to modify it to display the Id from data base as drop down list .... not enter the id by user
how can do it
<?php
session_start();
?>


<?xml version = "1.0" encoding = "utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">


<html>

 
<head>

<title>main </title>
 <link rel="stylesheet" type="text/css"
href="styles.css"/>



</head>

<body>

<form method="POST" action="see1.php">

<h1 align="left"><font face="Cooper Std Black" size="5"><p align="center">Enter Your ID to see 
the result of evaluation :</p></font><font face="Cooper Std Black" style="font-size: 35pt">
</font></h1>

	<p align="center"><input type="text" name="b" size="20"></p>

<h1 align="center"><font face="Cooper Std Black" style="font-size: 35pt">&nbsp;</font><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></h1>
</form>

</body>

</html>


Is This A Good Question/Topic? 0
  • +

Replies To: how retrieve from database as drop down list?

#2 sas1ni69  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 85
  • View blog
  • Posts: 431
  • Joined: 04-December 08

Re: how retrieve from database as drop down list?

Posted 15 March 2012 - 12:20 AM

You cannot retrieve it from the database as a drop down list so to say. But what you can do is retrieve rows from the database and cycle through them to populate the drop down list.


Something like this would do fine:

$sql = "SELECT * FROM users;
$result = mysql_query($sql);

echo "<select>";
while($row = mysql_fetch_array($result)) {
    echo "<option>" . $row['userId'] . "</option>";
} 
echo "</select>";





Edit: Apparently I spelled "retrieve" wrong.

This post has been edited by sas1ni69: 15 March 2012 - 12:22 AM

Was This Post Helpful? 1
  • +
  • -

#3 so0oma  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 93
  • Joined: 01-January 11

Re: how retrieve from database as drop down list?

Posted 15 March 2012 - 12:27 AM

thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1