将表单元格值放入PHP post
我在调整从我设置的表传递到将表单元格值放入PHP post,php,html,mysql,html-table,cell,Php,Html,Mysql,Html Table,Cell,我在调整从我设置的表传递到$\u POST的值时遇到问题 下面是用于设置表的代码: print "<form action=\"updateitem.php\" method=\"post\">\n"; print "<table border cellpadding = 3>\n"; print "<tr>\n"; print "<th>Menu item id</th>\n"; print "<th>Menu item
$\u POST
的值时遇到问题
下面是用于设置表的代码:
print "<form action=\"updateitem.php\" method=\"post\">\n";
print "<table border cellpadding = 3>\n";
print "<tr>\n";
print "<th>Menu item id</th>\n";
print "<th>Menu item name</th>\n";
print "<th>Menu</th>\n";
print "<th>Menu item price</th>\n";
print "</tr>\n";
while($info = mysql_fetch_array($results)){
$mi = explode("_",$info['meta_key']);
if ($mi[2] == "food")
$mi[2] = "takeout";
print "<tr>\n";
print "<td id=\"meta_id\">".$info['meta_id']."<input type=\"hidden\" name=\"meta_id".$i."\" value=\"".$info['meta_id']."\" /></td>\n";
print "<td>".$info['post_title']."</td>\n";
print "<td>".$mi[2]."</td>\n";
print "<td id=\"price\" contenteditable=\"true\">".$info['meta_value']."<input type=\"hidden\" name=\"meta_value".$i."\" value=\"".$info['meta_value']."\" /></td>\n";
print "</tr>\n";
$i++;
}
print "</table>\n";
print "<input type=\"Submit\" value=\"Update\" />\n";
print "</form>\n";
打印“\n”;
打印“\n”;
打印“\n”;
打印“菜单项id\n”;
打印“菜单项名称\n”;
打印“菜单”\n;
打印“菜单项价格\n”;
打印“\n”;
而($info=mysql\u fetch\u数组($results)){
$mi=explode(“_”,$info['meta_key']);
如果($mi[2]=“食品”)
$mi[2]=“外卖”;
打印“\n”;
打印“%$info['meta_id]”。\n;
打印“%$info['post_title']”。\n;
打印“%$mi[2]”。\n;
打印“.$info['meta_value']”。\n;
打印“\n”;
$i++;
}
打印“\n”;
打印“\n”;
打印“\n”;
我想做的是,当有人更改price单元格时,我希望更新后的price在PHP的
$\u POST
中传递。可能吗 这里的contenteditable
属性对您没有帮助。
您必须使用javascript来注意更改的时间,并对其进行处理
简单的答案是,您需要使
字段可供用户使用。因此,将type=“hidden”
更改为type=“text”
或添加另一个未隐藏的字段供用户交互,然后值将在$\u POST
中传递回脚本
建议的修改
print "<form action=\"updateitem.php\" method=\"post\">\n";
print "<table border cellpadding = 3>\n";
print "<tr>\n";
print "<th>Menu item id</th>\n";
print "<th>Menu item name</th>\n";
print "<th>Menu</th>\n";
print "<th>Menu item price</th>\n";
print "</tr>\n";
while($info = mysql_fetch_array($results)){
$mi = explode("_",$info['meta_key']);
if ($mi[2] == "food")
$mi[2] = "takeout";
print "<tr>\n";
print '<td id="meta_id">' . $info['meta_id'] . '<input type="hidden" name="meta_id[]" value="' . $info['meta_id'] . '" /></td>';
print '<td>'.$info['post_title'].'</td>';
print '<td>'.$mi[2].'</td>';
print '<td id="price">';
print '<input type="hidden" name="original_price[]" value="' . $info['meta_value'] . '" />';
print '<input type="text" name="price[]" value="' . $info['meta_value'] . '" />';
print '</td>';
print "</tr>\n";
$i++;
}
print "</table>\n";
print "<input type=\"Submit\" value=\"Update\" />\n";
print "</form>\n";
因此,您可以根据需要处理更改的价格
foreach ( $_POST['price'] as $i => $price ) {
if ( $price != $_POST['original_price'][$i]) {
// We have a price change lets update the database
// using $_POST['meta_id'][$i] as the key to the database table ? I assume ??
}
}
提交该表单时,表单字段“price”将提交到updateitem.php。有什么问题吗?嘿,RiggsFolly,谢谢你的回复。不幸的是,这似乎只给出一个结果,而不是整个表。谢谢,真的很抱歉,我收回了。使用foreach循环将显示每个项。谢谢你的帮助,真愚蠢!
foreach ( $_POST['price'] as $i => $price ) {
if ( $price != $_POST['original_price'][$i]) {
// We have a price change lets update the database
// using $_POST['meta_id'][$i] as the key to the database table ? I assume ??
}
}