$sql = "SELECT distinct s.doc_id, s.pat_id as pat_id, p.pat_fullname as fullname, p.pat_id from patient p, patientscript s WHERE s.doc_id = '$doc_id' AND s.status = '1' AND s.pat_id = p.pat_id;";
$result = mysql_query($sql) OR
die("Database Error. MYSQL-Error:".mysql_error()."\n");
echo "<form name='form'> ";
echo "<label>Patient :</label>";
echo "<select name='patname'>";
echo "<option>Select a patient</option>";
while ($row = mysql_fetch_array($result))
{
$patname = $row['fullname'];
$pat_id = $row['pat_id'];
echo "<option value='$patname'>$patname</option>";
}
echo "</select>";
echo "<input type='button' value='Submit' onClick='get();' >";
echo "<input type='hidden' name='pat_id' value='$pat_id'/>";
echo "</form>";
echo "<div id='showName'></div>";
假设选项值A和B有2个回声结果。 当选择A时,我从输出中得到12(id)A 当选择B时,我从输出中得到12(id)B 实际上12是B,A是7,任何人都可以帮我解决这个问题。
答案 0 :(得分:0)
试试这个:
(...)
echo "<select name='patdata'>";
echo "<option>Select a patient</option>";
while ($row = mysql_fetch_array($result))
{
$patname = $row['fullname'];
$pat_id = $row['pat_id'];
echo "<option value='".$patname."-".$pat_id."'>$patname</option>";
}
echo "</select>";
echo "<input type='button' value='Submit' onClick='get();' >";
echo "</form>";
(...)
然后,(我假设您在发布后获取结果)
$patdata = explode( '-', $_REQUEST['patdata']);
$patname = $patdata[0];
$pat_id = $patdata[1];