发布到PHP弹出窗口的可点击的HTML表格行 [英] Clickable HTML table rows that POST to a PHP popup window
问题描述
我有一个HTML表格,其中包含使用PHP生成的行并使用MySQL数据填充。我希望行是可点击的,在onclick中,他们用该行的MySQL数据打开一个新窗口。
我可以使用什么方法在点击后发布值并在新窗口中打开PHP页面而不会影响父页面?
我的行生成类似于此:
while($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC)){
echo
< tr onclick = \openDetails(。$ row ['id']。)\> // openDetails()现在不做任何操作...
td 。 $ row ['id']。 < / td>
< td> 。 $ row ['ser']。 < / td>
< td> 。 $ row ['part']。 < / td>
< td> 。 $ row ['model']。 < / td>
< td> 。 $ row ['make']。 < / td>
< td> 。 $ row ['description']。 < / td>
< td> 。 $ row ['price']。 < / td>
< / tr>;
openDetails();
认为JS(我对JQuery解决方案开放)是关键。总的想法是,有人点击行,他们得到assets_details.php(这将查询 WHERE id = $ _ POST ['id']
并填充表单)在一个新窗口,他们可以编辑和提交信息。如果POST是不可能的 $ _ SESSION
变量会做,我只是不知道如何设置onclick。
感谢@RamRaider的建议,但我对Ajax一无所知,我害怕使用我不完全了解的代码。
我想出了这个解决方案。我将表格封装在一个表格中,并创建了一个隐藏的输入,并为该行设置并提交onclick。
< form target ='_ blank'name ='getID'method ='POST'action ='asset_details.php'>
< input type ='hidden'name ='id'id ='id'>
< table>
while $($ row = mysqli_fetch_array($ result,MYSQLI_ASSOC)){
echo
< td> 。 $ row ['id']。 < / td>
< td> 。 $ row ['ser']。 < / td>
< td> 。 $ row ['part']。 < / td>
< td> 。 $ row ['model']。 < / td>
< td> 。 $ row ['make']。 < / td>
< td> 。 $ row ['description']。 < / td>
< td> 。 $ row ['price']。 < / td>
< / tr>
< / table>
< / form>;
JS:
函数selectID(id){
document.getID.id.value = $(this).closest('tr')。attr('id');
document.getElementsByName('getID')[0] .submit();
}
I have an HTML table that has rows generated with PHP and populated with MySQL data. I want the rows to be clickable, where onclick they open a new window with the MySQL data for that row.
What method can I use to POST a value on click and open the PHP page in a new window without disturbing the parent page? My rows are generated similar to this:
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "
<tr onclick=\"openDetails(" . $row['id'] . ")\"> //openDetails() does nothing for now…
<td>" . $row['id'] . "</td>
<td>" . $row['ser'] . "</td>
<td>" . $row['part'] . "</td>
<td>" . $row['model'] . "</td>
<td>" . $row['make'] . "</td>
<td>" . $row['description'] . "</td>
<td>" . $row['price'] . "</td>
</tr>";
openDetails();
does nothing but I thought JS (I'm open to JQuery solutions) was the key. The overall idea is that someone clicks the row and they get assets_details.php (Which will query for WHERE id=$_POST['id']
and populate a form) in a new window where they can edit and submit the information. If POST isn't possible a $_SESSION
variable would do, I just don't know how to set either "onclick".
Thanks @RamRaider for the suggestions but I know nothing of ajax and I'm afraid to use code that I don't fully understand.
I came up with this solution though. I wrapped the table in a form and created a hidden input that is set and submitted onclick for the row.
<form target='_blank' name='getID' method='POST' action='asset_details.php'>
<input type='hidden' name='id' id='id'>
<table>
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo "
<tr onclick=\"selectID('" . $row['id'] . "')\">
<td>" . $row['id'] . "</td>
<td>" . $row['ser'] . "</td>
<td>" . $row['part'] . "</td>
<td>" . $row['model'] . "</td>
<td>" . $row['make'] . "</td>
<td>" . $row['description'] . "</td>
<td>" . $row['price'] . "</td>
</tr>
</table>
</form>";
The JS:
function selectID(id) {
document.getID.id.value = $(this).closest('tr').attr('id');
document.getElementsByName('getID')[0].submit();
}
这篇关于发布到PHP弹出窗口的可点击的HTML表格行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!