【发布时间】:2018-07-13 05:59:59
【问题描述】:
我在其功能中动态创建按钮时遇到问题。我已经在 php 中完美地创建了一个表格,但我不知道如何使用每个按钮上的函数在 php 代码中创建一个按钮。
Example
ID NAME PRICE ADD
1 STRAW 100 BUTTON 1
2 STRAWRE 300 BUTTON 2
3 STRAWTO 200 BUTTON 3
按钮添加是动态使用 html 表内的循环。当我处理按钮上的单击时,id、name 和 price 项将随文本框一起更改,每个文本框都有一个使用旧文本框的自动值,并且按钮 1 将添加一个按钮左按钮 1,或者按钮 2 或按钮 3。
function cetakdata()
{
if(is_array($_SESSION['pembelian']))
{
$total = "";
echo "Here's your chart" . "<br>";
$max = count($_SESSION['pembelian']);
$th1 = "<th>" . "No" . "</th>";
$th2 = "<th>" . "Nama Barang" . "</th>";
$th3 = "<th>" . "Harga Barang" . "</th>";
$th4 = "<th>" . "Jumlah" . "</th>";
$th5 = "<th>" . "Subtotal" . "</th>";
$th6 = "<th>" . "Add Edit" . "</th>";
echo "<table border=1>";
echo "<tr>";
echo $th1 ;
echo $th2;
echo $th3;
echo $th4;
echo $th5;
echo $th6;
echo "</tr>";
for ($indexo = 0; $indexo < $max; $indexo++) {
echo "<tr>";
echo "<td>" . $indexo."</td>";
echo "<td>" . $_SESSION['pembelian'][$indexo]['namabarang']."</td>";
echo "<td>" . $_SESSION['pembelian'][$indexo]['hargabarang']."</td>";
echo "<td>" . $_SESSION['pembelian'][$indexo]['jumlahbarang']."</td>";
echo "<td>" . $_SESSION['pembelian'][$indexo]['subtotal']."</td>";
echo "<td>" .THIS IS HOW I PUT THE BUTTON ON THE FLY DELETE BUTTON."</td>";
$total += $_SESSION['pembelian'][$indexo]['subtotal'];
echo "</tr>";
}
echo "TOTAL BELANJA = ". $total;
echo "</table>";
}else
{
echo "Chart is still Empty";
}
}
这是代码。当创建按钮时,另一个 td 将使用其值更改为文本框,并且在用户完成编辑后,用户还可以将其保存在添加按钮旁边的保存按钮中,但是当用户单击编辑按钮时会出现保存按钮,如图像以上:
【问题讨论】:
-
您所描述的某些内容听起来像是需要在 javascript 而不是 php 中完成。客户端与服务器端。
-
任何答案都将不胜感激 :) 但我应该在 php 代码中连接按钮,因为它将在会话中处理
-
您能否包含一些您的 php 代码,以便我们查看您已有的内容?
-
我认为您需要发布一些代码或清理问题。你已经有了一个按钮,你想点击它做什么?
-
非常感谢,但是如何使用 php 示例连接此函数,例如此示例 imageshack.us/photo/my-images/831/exampleog.png
标签: php html-table