恩,写错了一些。。汗。。我近段时间做事显得很急噪,不知道为什么...... 应该是 foreach ($checkbox as $value) { $sqlstr="delete from table5 where id='$value"; mysql_query($sqlstr); }
for ($i=0;$i<count($checkbox);$i++) { if (Trim($checkbox[$i])!='') { $sqlstr="delete from table5 where id='$checkbox[$i]'"; ////产生SQL mysql_query($sqlstr); } }
surfchen(冲浪)大哥,我把分都给你,想在问一个问题,如果还有input,select什么的, 要怎么写? 这样写吗? foreach ($checkbox as $value;$input as $value1) { $sqlstr="delete from table5 where id='$value" and username='$value1'"; mysql_query($sqlstr); }
<td><input type="checkbox" name="checkbox[]" value=td> ..... $arr = array(); $arr = $_POST['checkbox']; $list = implode(",", $arr); $sqlstr="delete from table5 where id in ($list)";
defoliation(defoliation)写的把空格处理掉了.... 不过我觉得如果是自己用的话,不用这样做TRIM POST的值主要是用在做搜索页面的时候,防止别人乱来...如果既有数组又有非数组.... foreach ($_POST as $value) { if (is_array($value)) { foreach ($value as $sub_value) { $sqlstr="delete from table5 where id='$sub_value"; mysql_query($sqlstr); } } else { $sqlstr="delete from table5 where id='$value"; mysql_query($sqlstr); } }
slamdunk3(流川枫)的应该也可以实现,嘿嘿,我对数据库不是很熟悉.....
如果还有input,select什么的, 要怎么写? 这样写吗? foreach ($checkbox as $value;$input as $value1) { $sqlstr="delete from table5 where id='$value" and username='$value1'"; mysql_query($sqlstr); }
我最后贴出的代码可以处理所有的POST。不过你需要把某些POST过滤,比如sumit里的value <input type="submit" name="submit" /> foreach ($_POST as $value) { if (key($_POST)=='submit')//如果不行换这个if (array_keys($_POST, $value)=='submit') { continue; } if (is_array($value)) { foreach ($value as $sub_value) { $sqlstr="delete from table5 where id='$sub_value"; mysql_query($sqlstr); } } else { $sqlstr="delete from table5 where id='$value"; mysql_query($sqlstr); } }
$sqlstr="delete from table5 where id='$value" and username='$value1'";那个“ and username='$value1'”怎么处理啊!!!!,他也是数组啊
foreach ($checkbox as $key => $value) { $value1=$input[$key]; $sqlstr="delete from table5 where id='$value" and username='$value1'"; mysql_query($sqlstr); } 不过这样必须保证数组键对应相同如果不同,就要具体问题具体分析了....
我说具体一点吧:我的表单有: <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]\"></td> <td><input type=\"input\" name=\"input[]\" value=\"$arr[1]\"></td> <td><input type=\"input\" name=\"input1[]\" value=\"$arr[1]\"></td> 如果是单选的话$_post[$checkbox],$_post[$input],$_post[$input1]. 提交后$sqlstr="delete from table5 where id='$checkbox" and username="$input" and sex= "$input1"; 复选的话,怎么办? surfchen(冲浪)大哥,感激不尽
foreach ($checkbox as $value;$input as $value1) ~~~~~ 这也行。我没试过,不过估计会报错呵呵
我说具体一点吧:我的表单有: <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]\"></td> <td><input type=\"input\" name=\"input\" value=\"$arr[1]\"></td> <td><input type=\"input\" name=\"input1\" value=\"$arr[1]\"></td> 如果是单选的话$_post[$checkbox],$_post[$input],$_post[$input1]. 提交后$sqlstr="delete from table5 where id='$checkbox" and username="$input" and sex= "$input1"; 复选的话,怎么办?这样 $checkbox = join("','",$_POST['checkbox']; $input = $_POST['input']; $input1 = $_POST['input1'];$sqlstr = "delete from table5 where username='$input' and sex='$input1' and id in ('$checkbox')"; 无论单选还是复选都一样
5555~~~~还是没搞清楚 是这样的: $sqlstr="select * from table5 where userid='$userid' ; $result=mysql_query($sqlstr); while ($arr=mysql_fetch_row($result)){ echo" <tr> <td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]"></td> <td><input type=\"input\" name=\"input[]\" value=\"$arr[1]"></td> <td><input type=\"input\" name=\"input1[]\" value=\"$arr[2]"></td> </tr> ";} 也就是说有3个数组!!
$sqlstr=mysql_query("update table5 set time='$input',doctor='$input11' where id in ('$radio')" 其实我也就是想一次修改多条数据
为什么????? 我用defoliation(defoliation)大哥的 for ($i=0;$i<count($radio);$i++) { if (Trim($radio[$i])!='') { $sqlstr=mysql_query("update table5 set time='$input[$i]',doctor='$input1[$i]' where id= '$radio[$i]'") } } 怎么修改是input和input1的值老是从第一个数据算起,而不是从选中的算起
如果是一条数据,可以:$sqlstr="delete from table5 where id='$checkbox";mysql_query($sqlstr);多条的话,怎么办。
再加30分
{
$sqlstr="delete from table5 where id='$value";
mysql_query($sqlstr);
}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head><body><form name="form1" method="POST" action="1.php">
<p>
<input type="checkbox" name="select[]" value="1">
<input type="checkbox" name="select[]" value="2">
<input type="checkbox" name="select[]" value="3">
<input type="checkbox" name="select[]" value="4">
</select>
</p>
<p> <input type="submit" name="Submit" value="提交">
</p>
</form>
<?
if (array_key_exists('Submit', $_POST))
{
$abc=join($_POST['select']);
echo"$abc";
}
?>
</body>
</html>
应该是
foreach ($checkbox as $value)
{
$sqlstr="delete from table5 where id='$value";
mysql_query($sqlstr);
}
{
if (Trim($checkbox[$i])!='')
{
$sqlstr="delete from table5 where id='$checkbox[$i]'"; ////产生SQL
mysql_query($sqlstr);
}
}
要怎么写?
这样写吗?
foreach ($checkbox as $value;$input as $value1)
{
$sqlstr="delete from table5 where id='$value" and username='$value1'";
mysql_query($sqlstr);
}
.....
$arr = array();
$arr = $_POST['checkbox'];
$list = implode(",", $arr);
$sqlstr="delete from table5 where id in ($list)";
不过我觉得如果是自己用的话,不用这样做TRIM POST的值主要是用在做搜索页面的时候,防止别人乱来...如果既有数组又有非数组....
foreach ($_POST as $value)
{
if (is_array($value))
{
foreach ($value as $sub_value)
{
$sqlstr="delete from table5 where id='$sub_value";
mysql_query($sqlstr);
}
}
else
{
$sqlstr="delete from table5 where id='$value";
mysql_query($sqlstr);
}
}
要怎么写?
这样写吗?
foreach ($checkbox as $value;$input as $value1)
{
$sqlstr="delete from table5 where id='$value" and username='$value1'";
mysql_query($sqlstr);
}
<input type="submit" name="submit" />
foreach ($_POST as $value)
{
if (key($_POST)=='submit')//如果不行换这个if (array_keys($_POST, $value)=='submit')
{
continue;
}
if (is_array($value))
{
foreach ($value as $sub_value)
{
$sqlstr="delete from table5 where id='$sub_value";
mysql_query($sqlstr);
}
}
else
{
$sqlstr="delete from table5 where id='$value";
mysql_query($sqlstr);
}
}
{
$value1=$input[$key];
$sqlstr="delete from table5 where id='$value" and username='$value1'";
mysql_query($sqlstr);
}
不过这样必须保证数组键对应相同如果不同,就要具体问题具体分析了....
<td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]\"></td>
<td><input type=\"input\" name=\"input[]\" value=\"$arr[1]\"></td>
<td><input type=\"input\" name=\"input1[]\" value=\"$arr[1]\"></td>
如果是单选的话$_post[$checkbox],$_post[$input],$_post[$input1].
提交后$sqlstr="delete from table5 where id='$checkbox" and username="$input" and sex=
"$input1";
复选的话,怎么办?
surfchen(冲浪)大哥,感激不尽
~~~~~
这也行。我没试过,不过估计会报错呵呵
<td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]\"></td>
<td><input type=\"input\" name=\"input\" value=\"$arr[1]\"></td>
<td><input type=\"input\" name=\"input1\" value=\"$arr[1]\"></td>
如果是单选的话$_post[$checkbox],$_post[$input],$_post[$input1].
提交后$sqlstr="delete from table5 where id='$checkbox" and username="$input" and sex=
"$input1";
复选的话,怎么办?这样
$checkbox = join("','",$_POST['checkbox'];
$input = $_POST['input'];
$input1 = $_POST['input1'];$sqlstr = "delete from table5 where username='$input' and sex='$input1' and id in ('$checkbox')";
无论单选还是复选都一样
是这样的:
$sqlstr="select * from table5 where userid='$userid' ;
$result=mysql_query($sqlstr);
while ($arr=mysql_fetch_row($result)){
echo" <tr>
<td><input type=\"checkbox\" name=\"checkbox[]\" value=\"$arr[0]"></td>
<td><input type=\"input\" name=\"input[]\" value=\"$arr[1]"></td>
<td><input type=\"input\" name=\"input1[]\" value=\"$arr[2]"></td>
</tr> ";}
也就是说有3个数组!!
其实我也就是想一次修改多条数据
尽量少用table td tr吧......多用div..
我用defoliation(defoliation)大哥的
for ($i=0;$i<count($radio);$i++)
{
if (Trim($radio[$i])!='')
{
$sqlstr=mysql_query("update table5 set time='$input[$i]',doctor='$input1[$i]' where id= '$radio[$i]'")
}
}
怎么修改是input和input1的值老是从第一个数据算起,而不是从选中的算起
说一个题外话.....既然是题外话,大家就不要这么认真看了..呵呵
尽量少用table td tr吧......多用div..
汗,不至于吧。虽然听说高手都用div,但是div定位的话麻烦吧?总感觉div了,在不同分辨率下问题应该比较多吧。div有何有点?
你看这个,http://yubeinet.com/yugioh/ 的代码。。是不是觉得很舒服?一切的美化都放在了CSS里...table只建议用在表格数据的呈现上