Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1024897
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:50:46+00:00 2026-05-16T11:50:46+00:00

My function goes something like this function multiple_delete($checkbox, $table, $url, $picture1 = 0, $picture2

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T11:50:47+00:00Added an answer on May 16, 2026 at 11:50 am

    Any time you use return its going to halt the execution of the function and return. I think you may be looking for continue and/or break. Also why do all this with separate queries? I would:

    1. Use a SELECT...WHERE...IN to grab ALL the matching records for images.
    2. Loop through those records and delete the files, putting the primary key values of the images deleted in a second array.
    3. Use a DELETE...WHERE...IN query to kill all the records.

    That way you only hit the db twice. It might look something like the following:

    function multiple_delete($checkbox, $table, $url, $picture1 = 0, $picture2 = 0, $picture3 = 0){
        $count = count($checkbox);
        $select = sprintf('SELECT * FROM %s WHERE id IN (%s)', $table, implode(',',$checkbox));
        $imagesResult = mysql_query($select);
        $deletes = array();
        while(false !== ($record = mysql_fetch_array($imagesResult))
        {
    
          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);
            continue;
          }
          if( $picture1 !== 0 && $picture2 !== 0 && $picture3 == 0 ) 
          {
            $pic_1 = $picture1;
            $pic_2 = $picture2;
            unlink($pic_1);
            unlink($pic_2); 
            continue;  
          }
    
          $deletes[] = $record['id'];
        }
    
        $delete = sprintf('DELETE FROM %s WHERE id IN (%s)', $table, implode(',',$deletes));
        $result_delete_data = mysql_query($delete);
    
        alert('Deleted Successfully');
        redirect_url($url);
    
    }
    

    In the above the continue‘s are going to move you to the next iteration of the loop if the are processed… Likewise using a break instead 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 the if statements that those are in… You might not even need to use continue/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 redirect function does something with header to 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 an alert and I don’t know what you’ve made that do either but I assume it adds the message to a session variable for the page redirect sends them to?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The error was caused by a silly mistake made by… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer Have you first profiled the web application to identify where… May 16, 2026 at 4:08 pm
  • Editorial Team
    Editorial Team added an answer Here's one way: user=> (import [java.net URLEncoder]) java.net.URLEncoder user=> (str… May 16, 2026 at 4:08 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Suppose I have code something like this: #include boost/thread/mutex.hpp using boost::mutex; typedef mutex::scoped_lock lock;
What's the difference between var myView = function () { //something goes here };
I'd like to return a table cell's node value. The method text() however, goes
Let's say I've defined this model: class Identifier(models.Model): user = models.ForeignKey(User) key = models.CharField(max_length=64)
I've just read The Good Parts, and I'm slightly confused about something. Crockford's example
This is my first question on SO, so if it seems beyond dumb, please
I'm working on what it looked to be like a very simple feature which
I am trying to execute a loop with a JSON query inside it. My
I know calls to $(function(){ }) in jQuery are executed in the order that
I have a PHP script that I'm calling with the .post() function in jQuery.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.