When we are selecting a element from a dropdownlist it will display the value of that element but after that when we choose the next element from that dropdownlist it must display the value below the previous element.
I have done it till displaying the element but when next element is clicked the first one is not displaying.
Please help me to sort this out. I have created my code using HTML, AJAX and PHP.
<?php
$q = intval($_GET['q']);
$con = mysql_connect("localhost", "root", "", "registration");
if (!$con)
{
echo "Connection Failed..";
echo mysql_error($con);
}
$sql = "select * from dynamic where Id='".$q."'";
$result = mysql_query($con, $sql);
echo "<table border=3 bordercolor='pink' width=100 height=100>
<tr>
<th>Id</th>
<th>Name</th>
<th>Fathername</th>
<th>Age</th>
<th>Gender</th>
<th>Address</th>
</tr>";
while ($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".$row["Id"]."</td>";
echo "<td>".$row["Name"]."</td>";
echo "<td>".$row["Fathername"]."</td>";
echo "<td>".$row["Age"]."</td>";
echo "<td>".$row["Gender"]."</td>";
echo "<td>".$row["Address"]."</td>";
echo "</td>";
}
echo "</tables>";
mysql_close($con);
?>
<html>
<head>
<script>
function test(str) {
if (str == "") {
document.getElementById("tst").innerHTML="";
}
else {
if(window.XMLHttpRequest) {
xml = new XMLHttpRequest();
} else {
xml = new ActiveXObject("Microsoft.XMLHttp");
}
xml.onreadystatechange = function() {
if (xml.readyState == 4 && xml.status == 200) {
document.getElementById("tst").innerHTML = xml.responseText;
}
}
xml.open("GET", "mysqlajax.php?q=" + str, true);
xml.send();
}
}
</script>
<body>
<form>
<select name="User" onchange="test(this.value)">
<option value="">-Select user-</option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">S</option>
<option value="5">G</option>
<option value="6">S</option>
</select>
</form><br>
<b><div id="tst"></b></div>
</body>
</html>
Instead of overwriting innerHTML, try to append to it.
Try something like this:
HTML:
<html>
<head>
<script>
function test(str)
{
if(str=="")
{
document.getElementById("tst").innerHTML="";
}
else
{
if(window.XMLHttpRequest)
{
xml=new XMLHttpRequest();
}
else
{
xml=new ActiveXObject("Microsoft.XMLHttp");
}
xml.onreadystatechange=function()
{
if(xml.readyState == 4 && xml.status== 200)
{
var innerHTML = document.getElementById("tst").innerHTML;
innerHTML += xml.responseText;
document.getElementById("tst").innerHTML=innerHTML;
}
}
xml.open("GET","mysqlajax.php?q="+str,true);
xml.send();
}
}
</script>
<body>
<form>
<select name="User" onchange="test(this.value)">
<option value="">-Select user-</option>
<option value="1">a</option>
<option value="2">b</option>
<option value="3">c</option>
<option value="4">S</option>
<option value="5">G</option>
<option value="6">S</option>
</select>
</form><br>
<b>
<div id="tst"></div>
</body>
</html>
PHP:
<?php
$q=intval($_GET['q']);
//$con=mysql_connect("localhost","root","","registration");
//if(!$con)
//{
//echo "Connection Failed..";
//echo mysql_error($con);
//}
//$sql="select * from dynamic where Id='".$q."'";
//$result=mysql_query($con,$sql);
echo "<table border=3 bordercolor='pink' width=100 height=100>
<tr>
<th>Id</th>
<th>Name</th>
<th>Fathername</th>
<th>Age</th>
<th>Gender</th>
<th>Address</th>
</tr>";
//while($row=mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>".rand()."</td>";
echo "<td>".rand()."</td>";
echo "<td>".rand()."</td>";
echo "<td>".rand()."</td>";
echo "<td>".rand()."</td>";
echo "<td>".rand()."</td>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
//mysql_close($con);
?>
Response will be:
Related
I have this problem here where when I press the Add button, it should save my selected choices into my table in database.
But when I press it, my table in database did not receive any data.
Did I do something wrong with my code? I need to find a right way to save the data into my designated table.
Any help would be greatly appreciated. Thanks
<?php
include "..\subjects\connect3.php";
//echo "Connection successs";
$query = "SELECT * FROM programmes_list";
$result = mysqli_query($link, $query);
?>
<form name = "form1" action="dropdownindex.php" method="post">
<table>
<tr>
<td>Select Pragramme</td>
<td>
<select id="programmedd" onChange="change_programme()">
<option>select</option>
<?php while($row=mysqli_fetch_array($result)) { ?>
<option value="<?php echo $row["ID"]; ?>"><?php echo $row["programme_name"]; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr>
<td>Select intake</td>
<td>
<div id="intake">
<select>
<option>Select</option>
</select>
</div>
</td>
</tr>
<tr>
<td>Select Subjects</td>
<td>
<div id="subject">
<select >
<option>Select</option>
</select>
</div>
</td>
</tr>
<input type="submit" value="Add" name="send">
</table>
</form>
<?php
if(isset($_POST['Add'])) {
//print_r($_POST);
$course1 = implode(',',$_POST['programmedd']);
$course2 = implode(',',$_POST['intake']);
$course3 = implode(',',$_POST['subject']);
$db->query("INSERT INTO programmes(programme_registered, intake_registered, subjects_registered)
VALUES (' ".$course1." ',' ".$course2." ', ' ".$course3." ' )");
echo $db->affected_rows;
}
?>
<script type="text/javascript">
function change_programme()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?programme="+document.getElementById("programmedd").value,false);
xmlhttp.send(null);
document.getElementById("intake").innerHTML=xmlhttp.responseText;
if(document.getElementById("programmedd").value=="Select"){
document.getElementById("subject").innerHTML="<select><option>Select</option></select>";
}
}
function change_intake()
{
var xmlhttp=new XMLHttpRequest();
xmlhttp.open("GET","ajax.php?intake="+document.getElementById("intakedd").value,false);
xmlhttp.send(null);
document.getElementById("subject").innerHTML=xmlhttp.responseText;
}
</script>
//ajax.php
<?php
$dbhost = 'localhost' ;
$username = 'root' ;
$password = '' ;
$db = 'programmes' ;
$link = mysqli_connect("$dbhost", "$username", "$password");
mysqli_select_db($link, $db);
if (isset($_GET["programme"])) {
$programme = $_GET["programme"];
} else {
$programme = "";
}
if (isset($_GET["intake"])) {
$intake = $_GET["intake"];
} else {
$intake = "";
}
if ($programme!="") {
$res=mysqli_query($link, "select * from intakes where intake_no = $programme");
echo "<select id='intakedd' onChange='change_intake()'>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["intake_list"];
echo "</option>";
}
echo "</select>";
}
if ($intake!="") {
$res=mysqli_query($link, "select * from subject_list where subject_no = $intake");
echo "<select>";
echo "<option>" ; echo "Select" ; echo "</option>";
while($value = mysqli_fetch_assoc($res)) {
echo "<option value=".$value['ID'].">";
echo $value["subjects"];
echo "</option>";
}
echo "</select>";
}
?>
Your error is where you check for button click.
Change to this
If(isset($_POST['send']))
For future purposes and references, When doing the above, include the name attribute from your button and not the value attribute
I'm having issues getting my local Wordpress installation to properly grab data from a database. Im using xmlhttprequest to call a php file which has my database request and then sends it back. This all works on my local installation without Wordpress but once i moved it all over to a locla Wordpress im not getting any information back.
I was able to successfully add the Javascript XMLHttpRequest function to my php template and the function is called properly when I use the onchange event on dropdown select but doesnt seem to want to go over the other php request and start the db connection. Looking for any thoughts...thanks!
Drop down select on Index.php
<form method="get" action="./gardenguide.php">
<table>
<tr>
<td>Hardiness Zone</td>
<td>
<select name="zone" style="width:110px;" onchange="getVegetablesByZone(this.value)">
<option selected disabled>Select</option>
<option value="2a">Zone 2a</option>
<option value="2b">Zone 2b</option>
<option value="3a">Zone 3a</option>
<option value="3b">Zone 3b</option>
<option value="4a">Zone 4a</option>
<option value="4b">Zone 4b</option>
<option value="5a">Zone 5a</option>
<option value="5b">Zone 5b</option>
<option value="6a">Zone 6a</option>
<option value="6b">Zone 6b</option>
<option value="7a">Zone 7a</option>
<option value="7b">Zone 7b</option>
<option value="8a">Zone 8a</option>
<option value="8b">Zone 8b</option>
<option value="9a">Zone 9a</option>
<option value="9b">Zone 9b</option>
<option value="10a">Zone 10a</option>
<option value="10b">Zone 10b</option>
<option value="11a">Zone 11a</option>
<option value="11b">Zone 11b</option>
<option value="12a">Zone 12a</option>
<option value="12b">Zone 12b</option>
<option value="13a">Zone 13a</option>
<option value="13b">Zone 13b</option>
</select>
</td>
</tr>
</table>
<div id="results"><b></b></div>
</form>
JavaScript calling the XMLHTTP Request
function getVegetablesByZone(zone) {
if (zone == "") {
document.getElementById("results").innerHTML = "";
alert("works1");
return;
} else {
if (window.XMLHttpRequest) {
// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
} else {
// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("results").innerHTML = xmlhttp.responseText;
}
};
}
PHP called from Javascript
<?php
$q = $_GET['q'];
echo "LOL";
$con = mysqli_connect('localhost','user','pass');
if (!$con) {
die('Could not connect: ' . mysqli_error($con));
}
mysqli_select_db($con,"plants");
$sql="SELECT plant_name FROM plants WHERE plant_id IN (SELECT fk_plant_id from hardinesszone WHERE zone = '$q')";
$result = mysqli_query($con,$sql);
if (!$result) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
$display = "<table cellpadding=1 cellspacing=1 border=1>
<tr>";
$i=0;
while($row = mysqli_fetch_array($result)) {
if ($i < 3)
{
$display.= "<td><input type=\"checkbox\" name=\"v[]\" value=\"".$row['plant_name']."\"> " . $row['plant_name'] . "</td>";
}
else
{
$display.= "</tr><tr><td><input type=\"checkbox\" name=\"v[]\" value=\"".$row['plant_name']."\"> " . $row['plant_name'] . "</td>";
$i=0;
}
$i=$i+1;
}
$display .= "</tr></table>";
$display .= "<input type=\"submit\" class=\"btn btn-submit btn-lg\" id=\"submit\" value=\"Submit!\">";
echo $display;
mysqli_close($con);
?>
I'm working on this code I used Oracle HR database as my database, I'm trying to filter database results based on multiple select, but I keep getting this error:
Warning: oci_execute(): ORA-00933
Warning: oci_fetch_array(): ORA-24374
and no results, my code:
index.php
<html>
<head>
<title>Employees Search</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
function checkinput()
{
if(document.Form2.DEPARTMENT_ID.value=="" && document.Form2.MANAGER_ID.value=="")
{
alert("Please select department or manager!");
return;
}
document.Form2.submit();
}
</script>
</head>
<body>
<form method="get" name="Form2" id="Form2">
<select id="DEPARTMENT_ID" name="DEPARTMENT_ID">
<option value="">DEPARTMENT:</option>
<option value="90">90</option>
<option value="60">60</option>
<option value="100">100</option>
<option value="30">30</option>
</select>
<select id="MANAGER_ID" name="MANAGER_ID" >
<option value="">MANAGER ID:</option>
<option value="100">100</option>
<option value="102">102</option>
<option value="103">103</option>
<option value="108">108</option>
</select>
<input type="button" value=" Search " onclick="checkinput()" />
</form>
<br />
<div id="result">
<?php include "emp.php"; ?>
</div>
</body>
</html>
emp.php
<?php
$conn = oci_connect('hr', ' ', 'My-PC:1521/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
if(isset($_GET['DEPARTMENT_ID'])||isset($_GET['MANAGER_ID'])){
$DEPARTMENT_ID=$_GET['DEPARTMENT_ID'];
$MANAGER_ID=$_GET['MANAGER_ID'];
$sql="SELECT * FROM EMPLOYEES WHERE ";
if($DEPARTMENT_ID != "")
{
$sql = $sql."DEPARTMENT_ID=".$DEPARTMENT_ID;
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
else
{
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo " <table><tr><th>Employee No.</th><th>First Name</th><th>Last Name</th><th>PHONE NUMBER</th><th>Email</th><th>Job Title</th><th>MANAGER_ID</th><th>DEPARTMENT_ID</th></tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC )) {
echo "<tr>";
echo "<td>".$row['EMPLOYEE_ID']."</td>";
echo "<td>".$row['FIRST_NAME']."</td>";
echo "<td>".$row['LAST_NAME']."</td>";
echo "<td>".$row['PHONE_NUMBER']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['JOB_ID']."</td>";
echo "<td>".$row['MANAGER_ID']."</td>";
echo "<td>".$row['DEPARTMENT_ID']."</td>";
echo "</tr>";
echo"</table>";
}
}
?>
Everything seems correct expect SQL when Department and manager id is not null.
<?php
$conn = oci_connect('hr', ' ', 'My-PC:1521/XE');
if (!$conn) {
$e = oci_error();
trigger_error(htmlentities($e['message'], ENT_QUOTES), E_USER_ERROR);
}
if(isset($_GET['DEPARTMENT_ID'])||isset($_GET['MANAGER_ID'])){
$DEPARTMENT_ID=$_GET['DEPARTMENT_ID'];
$MANAGER_ID=$_GET['MANAGER_ID'];
$sql="SELECT * FROM EMPLOYEES WHERE ";
if($DEPARTMENT_ID != "")
{
$sql = $sql."DEPARTMENT_ID=".$DEPARTMENT_ID;
if($MANAGER_ID != "")
{
$sql = $sql."AND MANAGER_ID=".$MANAGER_ID;
}
}
else
{
if($MANAGER_ID != "")
{
$sql = $sql."MANAGER_ID=".$MANAGER_ID;
}
}
$stid = oci_parse($conn, $sql);
oci_execute($stid);
echo " <table><tr><th>Employee No.</th><th>First Name</th><th>Last Name</th><th>PHONE NUMBER</th><th>Email</th><th>Job Title</th><th>MANAGER_ID</th><th>DEPARTMENT_ID</th></tr>";
while ($row = oci_fetch_array($stid, OCI_ASSOC )) {
echo "<tr>";
echo "<td>".$row['EMPLOYEE_ID']."</td>";
echo "<td>".$row['FIRST_NAME']."</td>";
echo "<td>".$row['LAST_NAME']."</td>";
echo "<td>".$row['PHONE_NUMBER']."</td>";
echo "<td>".$row['EMAIL']."</td>";
echo "<td>".$row['JOB_ID']."</td>";
echo "<td>".$row['MANAGER_ID']."</td>";
echo "<td>".$row['DEPARTMENT_ID']."</td>";
echo "</tr>";
echo"</table>";
}
}
?>
Changed Line :
$sql = $sql."AND MANAGER_ID=".$MANAGER_ID;
May be reason as SQL failed to parse this query.
As If both are not empty and assumed 10 then you query will be looked like SELECT * FROM EMPLOYEES WHERE DEPARTMENT_ID=10 MANAGER_ID=10; which is not syntactically correct.
hi i'm working on triple dropdown for country, state, city using ajax and the reference link is : http://roshanbh.com.np/2008/01/populate-triple-drop-down-list-change-options-value-from-database-using-ajax-and-php.html. It successfully working but i need if a state has no city in db table then a new text box is appear and the entered values is store in php mysql. what coding i'm implement that. please give some ideas.
code:
Ajax:
<script language="javascript" type="text/javascript">
function getXMLHTTP() {
var xmlhttp = false;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e1) {
xmlhttp = false;
}
}
}
return xmlhttp;
}
function getState(countryId) {
var strURL = "findState.php?country=" + countryId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function () {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('statediv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
function getCity(countryId, stateId) {
var strURL = "findCity.php?country=" + countryId + "&state=" + stateId;
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function () {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('citydiv').innerHTML = req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
Form:
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Country</td>
<td width="150"><select name="country" onChange="getState(this.value)">
<option value="">Select Country</option>
<option value="1">USA</option>
<option value="2">Canada</option>
</select></td>
</tr>
<tr style="">
<td>State</td>
<td ><div id="statediv"><select name="state" >
<option>Select Country First</option>
</select></div></td>
</tr>
<tr style="">
<td>City</td>
<td ><div id="citydiv"><select name="city">
<option>Select State First</option>
</select></div></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table>
</form>
findstate.php
<?php
include('config.php');
$country = intval($_GET['country']);
$query = "SELECT id,statename FROM state WHERE countryid='$country'";
$result = mysql_query($query);
?>
<select name="state" onchange="getCity(<?php echo $country?>,this.value)">
<option>Select State</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value=<?php echo $row['id']?>><?php echo $row['statename']?></option>
<?php } ?>
</select>
findcity.php
<?php
include('config.php');
$countryId = intval($_GET['country']);
$stateId = intval($_GET['state']);
$query = "SELECT id,city FROM city WHERE stateid='$stateId'";
$result = mysql_query($query);
?>
<select name="city">
<option>Select City</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['city']?></option>
<?php } ?>
</select>
I want to show if there is no city in any state then a textbox will appear and it's value store to db.
Put this inside findcity.php file
<?php
include('config.php');
$countryId=intval($_GET['country']);
$stateId=intval($_GET['state']);
$query="SELECT id,city FROM city WHERE stateid='$stateId'";
$result=mysql_query($query);
if(mysql_num_rows($result) == 0) // no cities found
{
echo '<input type="textbox" name="city" />';
}
else // show select box
{
?>
<select name="city">
<option>Select City</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value><?php echo $row['city']?></option>
<?php } ?>
</select>
<?php
}
?>
Your findstate.php becomes this
<?php
include('config.php');
$country=intval($_GET['country']);
$query="SELECT id,statename FROM state WHERE countryid='$country'";
$result=mysqli_query($query);
if(mysqli_num_rows($result)==0):?>
<input type="text" name="state" value="" />
<? endif; ?>
<select name="state" onchange="getCity(<?=$country ?>,this.value)">
<option>Select State</option>
<?php while($row=mysqli_fetch_array($result)): ?>
<option value=<?= $row['id']?>><?= $row['statename']?></option>
<?php endwhile; ?>
</select>
Similarly change your findcity.php aswell.
Suggestions
Never use mysql* anymore use mysqli* or PDO as mysql* is depricated. Link
For some time I am battling to solve this problem but I am not coming to any conclusion so thought to seek some help here.
The problem is that I am getting a blank dropdown instead I should get list of cities populated from the database. Database connection is fine but I am not getting anything in my dropdown.
This is what I am doing:
<?php
require 'includes/connect.php'; - database connection
$country=$_REQUEST['country']; - get from form (index.php)
$q = "SELECT city FROM city where countryid=".$country;
$result = $mysqli->query($q) or die(mysqli_error($mysqli));
if ($result) {
?>
<select name="city">
<option>Select City</option>
$id = 0;
<?php while ($row = $result->fetch_object()) {
$src = $row->city;
$id = $id + 1;
?>
<option value= <?php $id ?> > <?php $src ?></option>
<?php } ?>
</select>
<?php } ?>
ajax script is this:
<script>
function getXMLHTTP() { //function to return the xml http object
var xmlhttp=false;
try{mlhttp=new XMLHttpRequest();}
catch(e) {
try{ xmlhttp= new ActiveXObject("Microsoft.XMLHTTP"); }
catch(e){ try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}
return xmlhttp;
}
function getCity(strURL) {
var req = getXMLHTTP();
if (req) {
req.onreadystatechange = function() {
if (req.readyState == 4) {
if (req.status == 200) {
document.getElementById('citydiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
</script>
This is my form code:
<form method="post" action="" name="form1">
<table width="60%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="150">Country</td>
<td width="150"><select name="country" onChange="getCity('findcity.php?country='+this.value)">
<option value="">Select Country</option>
<option value="1">New Zealand</option>
<option value="2">Canada</option>
</select></td>
</tr>
<tr style="">
<td>City</td>
<td ><div id="citydiv"><select name="city">
<option>Select City</option>
</select></div></td>
</tr>
</table>
</form>
I think the problem is where you are outputting the <option> tags.
Try using this block of code between your <select> tags.
<option>Select City</option>
<?php
$id = 0;
while ($row = $result->fetch_object()) {
$src = $row->city;
$id = $id + 1;
?>
<option value="<?php echo htmlspecialchars($id,ENT_QUOTES) ?>"><?php echo htmlspecialchars($src) ?></option>
<?php } ?>
Edit: To clarify, you didn't have any echo statements before the $id and $src variables. I added htmlspecialchars() as a habit to produce properly escaped html.
A few things to try:
If you request findcity.php manually in your browser with a city you know exist in the database, will i return the correct HTML?
Try with FireBug or another javascript debugger, to set a breakpoint in the onreadystatechange function and see if the returned values are as expected. Set the breakpoint at the first line of the function.
<input name="acname" type="text" id="acname" value="" maxlength="9">
Account Name </p>
<select name="src">
<option value="number"> :::: Select ::::</option>
<option value="did">DID</option>
<option value="tfn">TFN</option>
</select>
<span id="errmsg"></span> DID/TFN </p>
<select name="did" onchange='OnChange(this.form1.did);' >
<option value=""> :::: Select ::::</option>
<? $qry1 = mysql_query("SELECT * FROM ".NUMBERS." where Flag='1'") or die(mysql_error()) ;
while($res1 = mysql_fetch_array($qry1)) { ?>
<option value="<?=$res1['Numbers'] ?>"><?=$res1["Numbers"]?></option>
<? } ?>
</select>
SOURCE