Reputation: 833
I'm trying to make a bulk action. I have checkboxes,
<input type="checkbox" name="check_id[]" value="1">
<input type="checkbox" name="check_id[]" value="2">
<input type="checkbox" name="check_id[]" value="3">
I wanted to select values from mysql table for each selected checkboxes then use my function to delete data based on the fetched values. I tried,
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']);
}
The problem is that, there is no fetched mysql values based on $_POST['check_id']
even though im sure that i have manufacturers_image
where is manufacturers_id
is either 1,2 or 3.
Is there a correct way to accomplish this?
Upvotes: 0
Views: 200
Reputation: 1096
Change this line
$manufacturer = mysql_fetch_array($manufacturer_query);
to
$manufacturer = mysql_fetch_assoc($manufacturer_query);
Upvotes: 1
Reputation: 39704
It is returning an array ... you use while()
or you fetch first image
delete_image(DIR_IMAGES . $manufacturer[0]['manufacturers_image']);
Upvotes: 0