我在管理儀表板頁(yè)面中有一個(gè)鏈接,單擊該鏈接會(huì)顯示“醫(yī)生詳細(xì)信息”?,F(xiàn)在我希望管理員必須能夠單擊表中的選項(xiàng)鏈接,并在同一頁(yè)面中查看醫(yī)生的完整詳細(xì)信息(我可能會(huì)為此使用模式)。所以我的問(wèn)題是如何從表中獲取ID并將其發(fā)送到另一個(gè)php文件進(jìn)行數(shù)據(jù)庫(kù)查詢?我的用于生成有關(guān)醫(yī)生詳細(xì)信息的代碼(doctor-details.php)<?phprequire('config.php');$sql = "SELECT * FROM doctor";$result = mysqli_query($conn, $sql);$count = mysqli_num_rows($result);if($count > 0){ while($rows = mysqli_fetch_array($result)){ ?> <tr> <td><?php echo $rows['id'];?> </td> <td><?php echo $rows['f_name'];?></td> <td><?php echo $rows['l_name'];?></td> <td><?php echo $rows['email'];?></td> <td><?php echo $rows['contact_number'];?></td> <td><?php echo $rows['gender'];?></td> <td><a href=""> Options</a></td> </tr> <?php }}?>最后是我的ajax:$(document).ready(function(){ $("#load-doctor-data").click(function(){ $.ajax({ url: 'views/admin/doctor-details.php', type: 'POST', success: function(result){ $("#response-doctor").html(result); } }); }); }); //Hide table on login $("#show-doctor-details").hide(); $(document).ready(function(){ $("#load-doctor-data").click(function(){ $("#show-doctor-details").show(); $("#show-patient-details").hide(); }); });所以,要點(diǎn)是我想單擊選項(xiàng)并顯示 John Doe 的完整詳細(xì)信息。
1 回答

紅顏莎娜
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超13個(gè)贊
數(shù)據(jù)屬性是非常容易傳遞的數(shù)據(jù)。因此,當(dāng)?shù)谝淮巫芳訒r(shí),請(qǐng)確保選項(xiàng)字段中有 id,如下所示:
<td><a href="" class="options" data-id="<?php echo $rows['id'];?>"> Options</a></td>
現(xiàn)在您可以在點(diǎn)擊事件處理程序中獲取此 id,如下所示:
$(document).on('click','.options', function(){ var currentId = $(this).data('id'); ... });
另外,您不需要準(zhǔn)備兩份文件。您可以將兩個(gè)事件處理程序包裝在一個(gè)文檔中。
- 1 回答
- 0 關(guān)注
- 103 瀏覽
添加回答
舉報(bào)
0/150
提交
取消