Php更新mysql循环数据
我想在用户提交时更新循环数据 这是一张名为“T1”的表格:Php更新mysql循环数据,php,mysql,Php,Mysql,我想在用户提交时更新循环数据 这是一张名为“T1”的表格: id在T1中自动增加 我像这样循环我的数据: $query = DB::query("SELECT * FROM ".DB::table('land')." WHERE areacode = '$areaid'"); while($row = DB::fetch($query)) { $i = $i+1; $areacode = $row['areacode ']; $time = date("Y-m-d H:i
id
在T1中自动增加
我像这样循环我的数据:
$query = DB::query("SELECT * FROM ".DB::table('land')." WHERE areacode = '$areaid'");
while($row = DB::fetch($query)) {
$i = $i+1;
$areacode = $row['areacode '];
$time = date("Y-m-d H:i",($row['time']));
$type = $row['type'];
$price = $row['price'];
$rowid = $row['id'];
if ($type == 1){
$valuetype = '<label><input name="radio['.$i.']" type="radio" id="radio" value="1" checked="checked" />
normaltype</label>
<label><input type="radio" name="radio['.$i.']" id="radio" value="2" />hightype</label>';
}else{
$valuetype = '<label><input type="radio" name="radio['.$i.']" id="radio" value="1" />normaltype</label>
<label><input name="radio['.$i.']" type="radio" id="radio" value="2" checked="checked" />hightype</label>';
}
$sqlsearch .= '<tr><td>'.$rowid.'</td>
<td>'.$areaname.'</td>
<td>'.$valuetype.'</td>
<td>'.$price.'</td>
<td>'.$rowbuytimes.'</td>
</tr>';
}
include template('admincp_area');
if($_GET['mod'] =='updatearealand'){
//how to update the mysql when user submit the loop data
}
foreach ($_POST['radio'] as $rowid => $value) {
DB::query("UPDATE ".DB::table('land')." SET type=$value WHERE id='$rowid'");
}
$query=DB::query(“从“.DB::table('land')”中选择*”,其中areacode='$areaid');
while($row=DB::fetch($query)){
$i=$i+1;
$areacode=$row['areacode'];
$time=date(“Y-m-dh:i”,($row['time']);
$type=$row['type'];
$price=$row['price'];
$rowid=$row['id'];
如果($type==1){
$valuetype='0
正常类型
高型';
}否则{
$valuetype='normaltype
高型';
}
$sqlsearch.=''.$rowid'
“.$areaname。”
“.$valuetype。”
“.$price。”
“.$rowbuytimes。”
';
}
包括模板(“管理区域”);
如果($\u GET['mod']='updatearealand'){
//用户提交循环数据时如何更新mysql
}
我的模板编码是:
<form method="post" autocomplete="off" name="paynameform" action="plugin.php?id=admincp&do=area&areaid=1&mod=updatearealand" enctype="multipart/form-data" ><table width="100%" border="1" cellspacing="0" cellpadding="5">$sqlsearch</table><input name="" type="button" /></form>
$sqlsearch
我可以循环上面的数据,但我不知道当用户提交表单时如何更新循环数据。用户可以编辑的部分数据是收音机
请帮我看一下这件事,谢谢。您已经有了
name=“radio['.$i.]”“
,所以结果是一个数组。那很好,你可以把它们分开。为了使它们与数据库条目相匹配,您可以将其更改为使用行id而不是$i
:
<label><input name="radio['.$rowid.']" type="radio" value="1" />normaltype</label>
我不知道您使用的是什么DB框架,所以您应该调整它以防止SQL注入
foreach ($_POST['radio'] as $rowid => $value) {
DB::query("UPDATE ".DB::table('land')." SET type=$value WHERE id='$rowid'");
}