【问题标题】:How to get value of an input (checkbox input) in auto generated forms that displayed as table rows?如何在显示为表格行的自动生成表单中获取输入(复选框输入)的值?
【发布时间】:2016-04-14 03:26:13
【问题描述】:

我从数据库生成表格,将每个单元格分配为复选框值,将每一行分组为表格并将它们全部显示为表格,请参阅 [this]。1 当我单击按钮时,我如何获得特定的单元格值每个表单(行)都有相同的 id。我想将值作为查询参数传递来更新数据库表。我已经搜索了类似的技术,但仍然没有找到解决方案。

这段代码在一个游标获取循环中:

				<form class="tr" id="barisn" method="post" action="">
					<span class="td"><input type="checkbox" name="id" value="<?php $data[0]?>"/><label for="id"><?php echo $data[0]?></label></span>
					<span class="td"><input type="checkbox" name="name" value="<?php $data[1]?>" /><label for="name"><?php echo $data[1]?></label></span>
					<span class="td"><input type="checkbox" name="gender" value="<?php $gender?>" /><label for="gender"><?php echo $gender?></label></span>
					<span class="td"><input type="checkbox" name="sender" value="<?php $data[8]?>" /><label for="sender"><?php echo $data[8]?></label></span>
					<span class="td"><input type="checkbox" name="date" value="<?php $data[5]?>" /><label for="date"><?php echo $data[5]?></label></span>
					<span class="td"><input type="checkbox" name="time" value="<?php $data[6]?>" /><label for="time"><?php echo $data[6]?></label></span>
					<span class="td"><input type="checkbox" name="state" value="<?php $state?>" /><label for="state"><?php echo $state?></label></span>
					<div class="td">
						<button class="btn-rawuh" type="submit" form="barisn" value="Rawuh">Rawuh</button>
						<button class="btn-tundha" type="submit" form="barisn" value="Tundha">Tundha</button>
						<button class="btn-mlebet" type="submit" form="barisn" value="Mlebet">Mlebet</button>
					</div>
				</form>

【问题讨论】:

    标签: javascript php jquery checkbox sql-update


    【解决方案1】:

    你必须放置锚标签而不是像这样的按钮

    <a href="edit.php?id=<?php echo $here_ur_dynamic_PK_of_that_row[index_value] ?>">Edit</a>
    

    当您点击编辑按钮时,页面将重定向到 edit.php(您必须创建新的 php 文件)然后从 url 获取 id:

    echo $_GET method
    

    然后您将使用 id(使用查询)获取该特定行的详细信息。

    【讨论】:

    • 感谢 Rahul 的启发,所以现在......我很困惑我应该在其中放入什么索引参数。需要获取索引 0 和索引 7 的值。例如,当我单击第 4 行中的锚点“Rawuh”时,操作应该是获取第 4 行的索引 0 的值(逻辑中的索引 3)(“6”)和值锚文本(“Rawuh”)。我仍然困惑的是如何获得索引 3?
    • 参考此代码: $query_c_s_c= mysql_query("select id,country_name,state_name,city_name from stud_rec"); while($row_c_s_c= mysql_fetch_array($query_c_s_c)) { echo "".$row_c_s_c['country_name'].""; echo "".$row_c_s_c['state_name'].""; echo "".$row_c_s_c['city_name'].""; echo " 编辑记录."; echo " 删除记录.";回声“”; }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 2018-04-15
    • 2018-04-07
    相关资源
    最近更新 更多