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
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>';
?>

Link to comment
Share on other sites

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
Share on other sites

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

   

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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