0

我目前有一个由 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 对应于它所在的表的行'

如果有人可以帮助我,请做。如果您也需要,我会发布更多信息。谢谢。

4

2 回答 2

0

Not a method I use often but I think you need to include the section_id in the URL for your openDialog() call. e.g.

echo "<button class='element' onclick='javascript:openDialog(\"myurl.php?sectionid=${sectionid}\");'>Details</button>";

You can then include:

$sectionid=$_GET["sectionid"];

at the top of your modal window script.

Any help?

于 2013-06-18T22:40:13.117 回答
0

有一些快速修复以及正确过程的替代方法(但显然很长) 1. 在functions.php 中创建一个函数并将您的代码添加到那里的模态窗口。

  1. 单击“详细信息”链接时,使用 AJAX 调用此函数(使用 admin-ajax.php)

  2. 返回 HTML 以显示为来自方法的字符串并显示在模式窗口中。

如果需要更多详细信息或帮助,请告诉我。

于 2013-06-19T13:51:29.030 回答