My function goes something like this
function multiple_delete($checkbox, $table, $url, $picture1 = 0, $picture2 = 0, $picture3 = 0){
$count = count($checkbox);
for($j=0;$j<$count;$j++)
{
$delete_id = $checkbox[$j];
$query = "SELECT * FROM $table WHERE id = '$delete_id'";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
return true;
if( $picture1 !== 0 && $picture2 !== 0 && $picture3 !== 0)
{
$pic_1 = $picture1;
$pic_2 = $picture2;
$pic_3 = $picture3;
unlink($pic_1);
unlink($pic_2);
unlink($pic_3);
return true;
}
if( $picture1 !== 0 && $picture2 !== 0 && $picture3 == 0 )
{
$pic_1 = $picture1;
$pic_2 = $picture2;
unlink($pic_1);
unlink($pic_2);
return true;
}
}
for($i=0;$i<$count;$i++) {
$del_id = $checkbox[$i];
$sql = "DELETE FROM $table WHERE id='$del_id'";
$result_delete_data = mysql_query($sql);
}
alert('Deleted Successfully');
redirect_url($url);
return true;
}
In the above function if the first or second condition returns true, then will it continue over the for loop below or it will simply halt the script ?
If return true will halt the script then
EDIT: Is it ok if I remove the return statement from the if conditions? And is it necessary for us to define the return statement in a user defined function?
Any time you use
returnits going to halt the execution of the function andreturn. I think you may be looking forcontinueand/orbreak. Also why do all this with separate queries? I would:SELECT...WHERE...INto grab ALL the matching records for images.DELETE...WHERE...INquery to kill all the records.That way you only hit the db twice. It might look something like the following:
In the above the
continue‘s are going to move you to the next iteration of the loop if the are processed… Likewise using abreakinstead would stop the loop completely and move on to the next code block where you delete from the DB. I’m not really sure what you’re trying to do here with theifstatements that those are in… You might not even need to usecontinue/break… Can you could elaborate on what you actually need to do?The last bit beyond the database stuff doesn’t make sense either… I assume your
redirectfunction does something withheaderto send them to another page… and if that’s the case your function is going to stop when that happens so it doesn’t make sense to return any kind of result. Then you do analertand I don’t know what you’ve made that do either but I assume it adds the message to a session variable for the pageredirectsends them to?