PHP通过URL传递单独的表值

时间:2018-08-24 15:37:56

标签: php url html-table hyperlink

一段时间以来,我一直在尝试解决此问题,因此,我们将不胜感激。

我有一个循环播放并显示记录的HTML表。最后两列是批准或拒绝超链接(每一个都为相应的操作运行不同的脚本。这会通过URL传递票证编号的.row数据(工作正常)。

我现在要做的是在前面添加一列,其中包含一个文本区域,单击链接时,我希望该区域用于添加注释并将注释发送到下一页。我已经尝试过PHP和Javascript通过id获取元素,但似乎无法使其工作。我正在尝试传递id =“ feedback_comments”

while ($row = sqlsrv_fetch_array($stmt)){
        echo "<tr>";
        echo "<td class='open_inc_table'>" . "<a href='view_ticket.php?ticket_id=" . $row['ticket'] . "'>" . $row['ticket'] . "</a>" . "</td>";
        echo "<td class='open_start_table'>" . date_format($row['start_date'],"d/m/Y H:i:s") . "</td>";
        echo "<td class='open_start_table'>" . date_format($row['end_date'],"d/m/Y H:i:s") . "</td>";
        echo "<td class='open_priority_table'>" . $row['priority'] . "</td>";
        echo "<td class='open_priority_table'>" . $row['category'] . "</td>";
        echo "<td class='open_priority_table'>" . $row['system'] . "</td>";
        echo "<td class='open_description_table'>" . $row['description'] . "</td>";
        echo "<td class='open_description_table'>" . $row['resolution'] . "</td>";
        echo "<td class='open_description_table'>" . '<textarea rows="5" cols="50" id="feedback_comments"></textarea>' . "</td>";
        echo "<td class='open_system_table'>" . "<a href='ticket_feedback_approve.php?inc_id=" . $row['ticket'] . "&feedback_comments=" . "'>" . 'Approve' . "</a>" . "</td>";
        echo "<td class='open_system_table'>" . "<a href='ticket_feedback_reject.php?inc_id=" . $row['ticket'] . "'>" . 'Reject' . "</a>" . "</td>";
        echo "</tr>";
    }
        echo "</table>";

1 个答案:

答案 0 :(得分:0)

提供ID来锚定标签。编写一个函数,该函数使用setAttribute函数获取textarea的值并更新定位标记的href属性。使用onkeydown事件执行功能,并将传票作为updateHref函数的参数。

while ($row = sqlsrv_fetch_array($stmt)){
    echo "<tr>";
    echo "<td class='open_inc_table'>" . "<a href='view_ticket.php?ticket_id=" . $row['ticket'] . "'>" . $row['ticket'] . "</a>" . "</td>";
    echo "<td class='open_start_table'>" . date_format($row['start_date'],"d/m/Y H:i:s") . "</td>";
    echo "<td class='open_start_table'>" . date_format($row['end_date'],"d/m/Y H:i:s") . "</td>";
    echo "<td class='open_priority_table'>" . $row['priority'] . "</td>";
    echo "<td class='open_priority_table'>" . $row['category'] . "</td>";
    echo "<td class='open_priority_table'>" . $row['system'] . "</td>";
    echo "<td class='open_description_table'>" . $row['description'] . "</td>";
    echo "<td class='open_description_table'>" . $row['resolution'] . "</td>";
    echo "<td class='open_description_table'>" . '<textarea rows="5" cols="50" id='feedback_comments' onkeydown='updateHref(\"" . $row['ticket'] . "\")'></textarea>' . "</td>";
    echo "<td class='open_system_table'>" . "<a id="approve-link">" . 'Approve' . "</a>" . "</td>";
    echo "<td class='open_system_table'>" . "<a href='ticket_feedback_reject.php?inc_id=" . $row['ticket'] . "'>" . 'Reject' . "</a>" . "</td>";
    echo "</tr>";
}
    echo "</table>";

这是将更新批准链接的href的功能

function updateHref(ticket) {
    var comment = document.getElementById("feedback_comments").value;
    document.getElementById("approve-link").setAttribute('href', 'ticket_feedback_approve.php?inc_id=' + ticket + '&feedback_comments=' + comment);
}