我正在开发PHP Phalcon。
我有一张桌子。该表的行数是动态的。我想点击一行并获取第一列中的值。这是我的html表格:
<?php
$counter = count($prescriptions);
$i = 0;
if ($counter == 0 )
{ echo "You have no earlier prescriptions." ;}
else {
?>
<Table class="inbox_table" cellspacing="0" style="width: 998px">
<tr>
<td class="inbox_table_cell inbox_table_heading">ID</td>
<td class="inbox_table_cell inbox_table_heading">Doctor ID</td>
<td class="inbox_table_cell inbox_table_heading">Patient Name</td>
<td class="inbox_table_cell inbox_table_heading">Ailment</td>
<td class="inbox_table_cell inbox_table_heading">Date</td>
</tr>
<?php
While ($i < $counter)
{
?>
<tr onclick="">
<td class="inbox_table_cell" id="ID"><?php echo $prescriptions[$i]->ID; ?></td>
<td class="inbox_table_cell" id="Doc_ID"><?php echo $prescriptions[$i]->Doctor_ID; ?></td>
<td class="inbox_table_cell" id="P_Name"><?php echo $patient_name; ?></td>
<td class="inbox_table_cell" id="Ailment"><?php echo $prescriptions[$i]->Ailment; ?></td>
<td class="inbox_table_cell" id="Date"><?php echo $prescriptions[$i]->Date_; ?></td>
</tr>
<?php
$i++;
}
}
?>
</Table
>
以下是相关的操作方法:
public function PrescriptionTableAction(){
//Select the earlier prescriptions of the online patient.
$current_PID = $this->session->current_patient_ID;
$get_prescriptions = "Select Doctor_ID,Patient_ID,Ailment,ID,Date_ from Prescriptions where Patient_ID = '$current_PID'";
$this->view->prescriptions = $this->modelsManager->executeQuery($get_prescriptions);
$this->view->patient_name = $this->session->current_patient->Full_Name;
}
我想做的事:
抽象地说,当我点击表中的一行时,它会打开一个完整处方的视图,其中包括药物的名称和每种药物的说明、开具处方的医生的姓名等等
更具体地说,当我点击一行时,我想从"ID"列中获得该行的值。(它对应于处方表数据库中的主键)。我想将此值传递给同一控制器中的另一个操作方法,在该方法中,可以从数据库中获取处方的详细信息,然后在相应的视图中显示。
我在这个网站上读过类似的问题和解决方案,但几乎所有的解决方案都提供了"警报"。我想把值传回控制器,我该怎么做?
我已经按照我想要的方式解决了这个问题;使用简单的javascript。
这是我的脚本函数:
function func(e){
var id = e.target.parentNode.firstElementChild.innerText;
window.location.href = "ActionMethod?id=" + id;
}
在我看来,我做了这个编辑:
<tr onclick="func(event)">
...
</tr>
这解决了我的问题!