Jump to content

[SOLVED] PHP COMBOBOX problem SOLVED THNX!!!


plodos

Recommended Posts

Dbase department

CREATE TABLE department (
   dept_id INT NOT NULL,
   dept_name TEXT,
   PRIMARY KEY (dept_id)
);

combobox code

<?php 
  echo'<select name="department">';
  $res=mysql_query("select * from department");
  if(mysql_num_rows($res)==0) 
  echo "there is no data in table..";
  else
  for($i=1;$i<=mysql_num_rows($res);$i++) {
  $row=mysql_fetch_assoc($res);
  echo"<option>$row[dept_name]</option>";
  }
echo'</select>';
?>

 

it is listing the department names....but I need to take IDs...

 

1 PEDIATRICS

2 DIABETES

3 CARDIOLOGY

 

How to use selectedIndex or how can I get the number of selected ındex

Link to comment
https://forums.phpfreaks.com/topic/106851-solved-php-combobox-problem-solved-thnx/
Share on other sites

<?php 
  echo'<select name="department">';
  $res=mysql_query("select * from department");
  if(mysql_num_rows($res)==0) 
  echo "there is no data in table..";
  else{
while ($row = mysql_fetch_assoc($res){
$id = $row['dept_id'];
$name = $row['dept_name'];
print "<option id='$id'>$name</option>\n";
}
  }
echo'</select>';
?>

Dbase department

CREATE TABLE department (
   dept_id INT NOT NULL,
   dept_name TEXT,
   PRIMARY KEY (dept_id)
);

combobox code

<?php 
  echo'<select name="department">';
  $res=mysql_query("select * from department");
  if(mysql_num_rows($res)==0) 
  echo "there is no data in table..";
  else
  for($i=1;$i<=mysql_num_rows($res);$i++) {
  $row=mysql_fetch_assoc($res);
  echo"<option>$row[dept_name]</option>";
  }
echo'</select>';
?>

 

it is listing the department names....but I need to take IDs...

 

1 PEDIATRICS

2 DIABETES

3 CARDIOLOGY

 

How to use selectedIndex or how can I get the number of selected ındex

<?php 
<form action="_update.php" method="post" id="_editform" >
  	echo'<select name="proficiency">';
  	$res=mysql_query("select * from proficiency");
  	if(mysql_num_rows($res)==0)
  	{
  		echo "there is no data in table..";
  	}
  	else
  	{
  		while ($row = mysql_fetch_assoc($res) )
  		{
  		$id = $row['p_id'];
	$name = $row['p_name'];
	print "<option id='$id'>$name</option>\n";
    }
    }
echo'</select>';

<input type="submit" name="Submit" value="SAVE ">
</form>
?>

 

_update.php

$_p_id    = $_POST['proficiency'];    // it show the selected name            

How can I take the OPTON ID 

$_p_id    = $_POST['id']; //it is not working

   

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.