我目前有一个由 sql 查询生成的表。该页面的网址是http://skunkboxstudios.com/dev/ofa-courses/
在表格中,每一行都有一个按钮,显示一个模式窗口,显示它所在行的更多详细信息。如何告诉模态窗口仅选择有关其所在行的信息。
这是页面上表格的代码:
global $wpdb;
$courses = $wpdb->get_results("SELECT * FROM section_view;");
$results = array();
echo "<table>";
echo "<tr>";
echo "<th>Section Name</th>";
echo "<th>Section Description</th>";
echo "<th>Start Date</th>";
echo "<th>End Date</th>";
echo "<th>Location</th>";
echo "<th>Details</th>";
echo "</tr>";
foreach($courses as $course){
$sectionname = "$course->section_name";
$sectiondescription = "$course->section_description";
$sectionstartdate = "$course->term_startdate";
$sectionenddate = "$course->term_enddate";
$sectionlocation= "$course->location_name";
$sectionid = "$course->section_id";
echo "<tr>";
echo "<td>$sectionname</td>";
echo "<td>$sectiondescription</td>";
echo "<td>$sectionstartdate</td>";
echo "<td>$sectionenddate</td>";
echo "<td>$sectionlocation</td>";
echo "<td>$sectionid</td>";
echo "<td>";
echo "<button class='element' onclick='javascript:openDialog();'>Details</button>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
模态窗口的代码在这里:
$details = $wpdb->get_results(
"SELECT * FROM section_view WHERE section_id = '$sectionid';");
foreach($details as $detail){
echo "<h2>".$detail->section_name."</h2>";
echo "<table>";
echo "<tr>";
echo "<td>".$detail->section_name."</td>";
echo "<td>".$detail->section_description."</td>";
echo "</tr>";
echo "</table>";
}
echo "<button class='element' onclick='javascript:closeDialog();'>Close</button>";
所以我需要在模式窗口中查询 SELECT * FROM section_view WHERE section_id = 'the section_id 对应于它所在的表的行'
如果有人可以帮助我,请做。如果您也需要,我会发布更多信息。谢谢。