使用数组从html表中获取记录并更新数据库 [英] Using arrays to take records from a html table and update database
问题描述
你好
需要一个合适的解决方案的帮助。
我已将记录提取到三列''类别'下的表中,
''评论''和分享(类别列还包含隐藏字段中
记录的索引号)
我希望用户能够编辑表中的数据,所以我将
的记录提取到hiddenfield,textareas,下拉列表和
复选框,以便他们可以进行更改。
我将这些元素命名为数组,并希望运行一个sql来获取
中的每一行(以及所做的任何更改)并更新mysql表。我做了一些
类似只有一个记录,但我仍然坚持如何使用
数量的表格元素的数组
我的表格代码如下,但我不知道脚本应该如何运行
表格被提交以依次添加每一行
帮助非常感谢
Ian
********************************** **************** ********************
< form action =" ; commentselect.php"方法= QUOT;交" enctype =" multipart / form-data"
name =" UpdateComments">
< table width =" 100%"边界=" 0" CELLPADDING = QUOT; 0" cellspacing =" 2"
bgcolor =" #FFFFFF">
< tr align =" center" class =" ListHeading">
< td width =" 20%" height =" 31"> Category< / td>
< td width =" 60%" height =" 31">评论< / td>
< td width =" 10%" height =" 31"> Share< / td>
< / tr>
< tr class =" BodyText">
<?php
while($ row =& mysql_fetch_array($ commentresults)){
extract($ row);
>
if($ i%2){
$ class =''row1'';
echo"< TR bgcolor = \" #CCCCCC \ &&;> \ n";
}其他{
$ class =''row2'';
echo"< TR bgcolor = \" white \"> \ n" ;;
}
$ i + = 1;
?>
< td width =" 20%"对齐= QUOT;左" class =" bodytext">< select
name =" category []" style =" WIDTH:90%">
< option value ="<?php echo $ row [''TypeID'']; ?>"><?php echo $ row [''typedesc''];
?>< / option>
<?php
$ commenttype = mysql_query(" SELECT * FROM commenttype WHERE username =
''$ username''");
if(b) !$ commenttype){
exit(''< p>执行查询时出错:''。mysql_error()。''< / p>'');
}
while($ row1 =& mysql_fetch_array($ commenttype)){
extract($ row1);
?>
< option value ="<?php echo $ row1 [''TypeID'']; ?>"><?php echo
$ row1 [''typedesc'']; ?>< br>
< / option>
<?php
}
? >
< / select>
< input name =" commindex []"类型= QUOT;隐藏" value ="<?php echo $ commindex;
?>">< / td>
< td width =" 60%" ;对齐= QUOT;左"类= QUOT; bodyText的" < textarea
name =" comm []"行= QUOT; 2英寸style =" WIDTH:99%"><?php echo $ comment;
?>< / textarea>< / td>
< ; td width =" 10%"对齐= QUOT;中心" class =" bodytext">< input type =" checkbox"
name =" avail []"值= QUOT;复选框" <?php share($ available); ?> < / td>
< / tr>
<?php
}
?>
< / table>
< / form>
************ ************************************** **********
Hello
Needing help with a suitable solution.
I have extracted records into a table under three columns ''category'',
''comment'' and share (the category column also holds the index no of the
record in a hidden field)
I wish the user to be able to edit the data in the table, so I have
extracted the records into hiddenfield, textareas, dropdown list and
checkbox so that they can make changes.
I named these elements as arrays and wish to run an sql to take each row in
turn (and any changes made) and update the mysql table. I did something
similar with just one record but am stuck as to how I use the arrays of a
number of form elements together
My code for the table is below but I dont know how the script should go when
the form is submitted to add each row in turn
Help greatly appreciated
Ian
************************************************** ********************
<form action="commentselect.php" method="post" enctype="multipart/form-data"
name="UpdateComments">
<table width="100%" border="0" cellpadding="0" cellspacing="2"
bgcolor="#FFFFFF">
<tr align="center" class="ListHeading">
<td width="20%" height="31">Category</td>
<td width="60%" height="31">Comment</td>
<td width="10%" height="31">Share</td>
</tr>
<tr class="BodyText">
<?php
while($row =& mysql_fetch_array($commentresults)) {
extract($row);
if ($i%2) {
$class = ''row1'';
echo "<TR bgcolor=\"#CCCCCC\">\n";
} else {
$class = ''row2'';
echo "<TR bgcolor=\"white\">\n";
}
$i += 1;
?>
<td width="20%" align="left" class="bodytext"><select
name="category[]" style="WIDTH: 90%">
<option value="<?php echo $row[''TypeID'']; ?>"><?php echo $row[''typedesc''];
?></option>
<?php
$commenttype = mysql_query("SELECT * FROM commenttype WHERE username =
''$username''");
if (!$commenttype) {
exit(''<p>Error performing query: '' . mysql_error() . ''</p>'');
}
while($row1 =& mysql_fetch_array($commenttype)) {
extract($row1);
?>
<option value="<?php echo $row1[''TypeID'']; ?>"><?php echo
$row1[''typedesc'']; ?><br>
</option>
<?php
}
?>
</select>
<input name="commindex[]" type="hidden" value="<?php echo $commindex;
?>"></td>
<td width="60%" align="left" class="bodytext" <textarea
name="comm[]" rows="2" style="WIDTH: 99%"><?php echo $comment;
?></textarea></td>
<td width="10%" align="center" class="bodytext"><input type="checkbox"
name="avail[]" value="checkbox" <?php share($available); ?> </td>
</tr>
<?php
}
?>
</table>
</form>
************************************************** **********
推荐答案
row =& mysql_fetch_array(
row =& mysql_fetch_array(
commentresults)){
extract(
commentresults)) {
extract(
row);
if(
row);
if (
这篇关于使用数组从html表中获取记录并更新数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!