I'm new in PHP
how can retrive data from database using dropdown list
?
I have created the dropdown menu

<select name="con_st" >
            <?php
$sql = "SELECT distinct con_stat FROM contst ";

$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
  echo "<option value=\"".$row['con_stat']."\">".$row['con_stat']."\n  ";
}
?></select>

any help?

try this:

<select name="con_st" >
<?php
$sql = "SELECT distinct con_stat FROM contst";

// $rs = mysql_query($sql); // you can eliminate this code

while($row = mysql_fetch_array($sql)) // change $rs into $sql
{
echo "<option value='$row[con_stat]'>".$row."</option>";
}
?>
</select>

this code work
i isked when click on drop down how retrive data from table
for example i want to use this dropdown to retrieve data from table pers?
"on change dropdown"

like this:

<select name="con_st" onChange="getData('current_page.php',this.value);" >

in javascript

function getData(page,x)
{
	window.location=page+"?dropdownid="+x;
}

in current_page.php
write your code and with the query string $_GET
like this:

if(isset($_GET['dropdownid']))
{
   $q="select * from your_tbl where your_field="+$_GET['dropdownid'];
// your code here
}

i added this code to current_page.php but no thing change when dropdown changed

<?php
if(isset($_GET['dropdownid']))
{
   $q="select * from cont where cont_status="+$_GET['dropdownid'];
   $r=mysql_query($q);
   while($row=mysql_fetch_array($r))
   {
   echo $row['cont_status'];
   }

}?>

and i want output at same page
............

what do you want to do after selecting your drop down?

Retrieve data from table cont at same page
like attachment

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.