我正在尝试进行批量操作。 我有复选框,
<input type="checkbox" name="check_id[]" value="1">
<input type="checkbox" name="check_id[]" value="2">
<input type="checkbox" name="check_id[]" value="3">
我想从mysql表中为每个选中的复选框选择值,然后使用我的函数根据获取的值删除数据。我试过了,
for( $i = 0; $i < count( $_POST['check_id'] ); $i++ ) {
$manufacturers_id = prepare_input($_POST['check_id'][$i]);
$manufacturer_query = mysql_query("select manufacturers_image from " . TABLE_MANUFACTURERS . " where manufacturers_id = '" . (int)$manufacturers_id . "'");
$manufacturer = mysql_fetch_array($manufacturer_query);
delete_image(DIR_IMAGES . $manufacturer['manufacturers_image']);
}
问题在于,即使我确定$_POST['check_id']
manufacturers_image
为1,2或3,也没有基于manufacturers_id
获取的mysql值。
有没有正确的方法来实现这个目标?
答案 0 :(得分:1)
更改此行
$manufacturer = mysql_fetch_array($manufacturer_query);
到
$manufacturer = mysql_fetch_assoc($manufacturer_query);
答案 1 :(得分:0)
它返回一个数组......你使用while()
或者你获取第一张图像
delete_image(DIR_IMAGES . $manufacturer[0]['manufacturers_image']);