0

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?

3
Contributors
6
Replies
8
Views
6 Years
Discussion Span
Last Post by altarek
0

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>

0

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"

0

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
}

Edited by Shanti C: n/a

0

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

Edited by altarek: n/a

0

Retrieve data from table cont at same page
like attachment

Edited by altarek: n/a

Attachments ex.jpg 20.21 KB
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.