PHP 数据批量更新 本帖最后由 xiachao2008 于 2011-10-24 18:17:11 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在列表页面把id传过去,,在编辑页面形成一个二维数组就好办了。$data=array( array('11','11','11'), array('22','22','22'), array('','33','33'),)然后遍历插入数据库即可。 不知道你的批量修改是什么意思 是所有的tr中的td全部变成输入框还是某一个tr? <input name="a[]" value="1"><input name="a[]" value="2">程序:$_POST['a'] 就是array("1","2") 在你们的帮助下总于快完成了,我改成了这样,但是还差最后一小点问题。update.php页面:if(isset($_POST["act"]) && $_POST["act"]="act"){ $array_id=$_POST["id"]; $array_content=$_POST["content"]; $array_apple=$_POST["apple"]; $date=array($array_id,$array_content,$array_apple); for($i=0,$size=count($date);$i<$size;$i++){ $update_sql="update exmple set content='{$_POST["content"][$i]}' ,apple='{$_POST["apple"][$i]}' where id = {$_POST["id"][$i]}"; $update_sql.=";"; mysql_query($update_sql); echo $update_sql;} index.php页面 $sql="select *from exmple"; $rs=mysql_query($sql); $count_result=mysql_num_rows($rs); echo $count_result."</br>"; echo "<table>"; while($new=mysql_fetch_array($rs)) { echo "<tr>"; echo "<td><input name=id[] value=$new[id] ></td>"; echo "<td><input name=content[] value=$new[content] ></td>"; echo "<td><input name=apple[] value=$new[apple] ></td>"; echo "</tr>"; } echo "</table>";?><input type="hidden" name="act" value="act"></input><input type="submit" name="submit"></input> </form>批量修改不成功,但是我把SQL语句输出来,放在PHPmyadmin里去执行,是成功了的。这是怎么回事啊?? if(isset($_POST["act"]) && $_POST["act"]="act"){ $array_id = $_POST["id"]; $array_content = $_POST["content"]; $array_apple = $_POST["apple"]; for($i=0;$i<count($array_id);$i++){ echo $update_sql=" UPDATE `exmple` SET content='{$array_content[$i]}' ,apple='{$array_apple[$i]}' where id = {$array_id[$i]}"; //mysql_query($update_sql); echo "<br/>"; }} 感谢,是我忘记在update里写数据库连接了 部署这个环境真的让我焦头烂额了,各位大大能不能帮我看看! php 中关于类的调用出错supplied argument is not a valid MySQL-Link resource in session_start()问题 奇怪的问题 wordpress的源代码中查询不到对mysql数据库操作的代码 谁有“http协议详解”的东西啊 请大虾帮我看看我的代码 大家提供些信息吧,想租个空间 mysql表改了编码,语句执行就报错 看看这个PHP错误该如何配置来解决?谢谢! 为什么能这样赋值? 让用户自定义文本文字的格式 求改代码
$data=array(
array('11','11','11'),
array('22','22','22'),
array('','33','33'),
)
然后遍历插入数据库即可。
<input name="a[]" value="2">程序:$_POST['a'] 就是array("1","2")
update.php页面:if(isset($_POST["act"]) && $_POST["act"]="act")
{
$array_id=$_POST["id"];
$array_content=$_POST["content"];
$array_apple=$_POST["apple"];
$date=array($array_id,$array_content,$array_apple); for($i=0,$size=count($date);$i<$size;$i++){
$update_sql="update exmple set content='{$_POST["content"][$i]}' ,apple='{$_POST["apple"][$i]}' where id = {$_POST["id"][$i]}";
$update_sql.=";";
mysql_query($update_sql);
echo $update_sql;} index.php页面 $sql="select *from exmple";
$rs=mysql_query($sql);
$count_result=mysql_num_rows($rs);
echo $count_result."</br>";
echo "<table>";
while($new=mysql_fetch_array($rs))
{
echo "<tr>";
echo "<td><input name=id[] value=$new[id] ></td>";
echo "<td><input name=content[] value=$new[content] ></td>";
echo "<td><input name=apple[] value=$new[apple] ></td>";
echo "</tr>"; }
echo "</table>";
?>
<input type="hidden" name="act" value="act"></input>
<input type="submit" name="submit"></input>
</form>
批量修改不成功,但是我把SQL语句输出来,放在PHPmyadmin里去执行,是成功了的。这是怎么回事啊??
if(isset($_POST["act"]) && $_POST["act"]="act")
{
$array_id = $_POST["id"];
$array_content = $_POST["content"];
$array_apple = $_POST["apple"];
for($i=0;$i<count($array_id);$i++){
echo $update_sql=" UPDATE `exmple` SET content='{$array_content[$i]}' ,apple='{$array_apple[$i]}' where id = {$array_id[$i]}";
//mysql_query($update_sql);
echo "<br/>";
}
}
是我忘记在update里写数据库连接了