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 8539093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:16:52+00:00 2026-06-11T11:16:52+00:00

I’m trying to set up an admin page where I’ll be able to select

  • 0

I’m trying to set up an admin page where I’ll be able to select images from a gallery with check boxes in a web-form then remove the images from the file system as well as the database. The issue I’m having is how I should update the database.

As you can see in the model, I currently update the database after each file was removed, the just keep count of how many were removed and subtracting that from the “old” order number since image 23 after 10 images before it were removed would end up being image 23-10 = 13). Not sure if there might be a few break cases where this wont work.

It seems to work but noticed if the gallery has a lot of pictures the database order id doesn’t get updated after 35. I’m wondering if that might be some limit like how many connections can be made to the database in a given amount of time? Is there a way I could store all the order id’s and update them all at once or is making a connection to the database each time correct(I’m doubting since that seems like bad practice)?

The web-form:

<form action="http://localhost/admin/galleryRemove" method="post" enctype="multipart/form-data">
    <input type="checkbox" name="orderID[]" value="1"  />
    <img src="http://localhost/img/galleries/001/img01.jpg" alt="1" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="2"  />
    <img src="http://localhost/img/galleries/001/img02.jpg" alt="2" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="3"  />
    <img src="http://localhost/img/galleries/001/img03.jpg" alt="3" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="4"  />
    <img src="http://localhost/img/galleries/001/img04.jpg" alt="4" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="5"  />
    <img src="http://localhost/img/galleries/001/img05.jpg" alt="5" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="6"  />
    <img src="http://localhost/img/galleries/001/img06.jpg" alt="6" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="7"  />
    <img src="http://localhost/img/galleries/001/img07.jpg" alt="7" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="8"  />
    <img src="http://localhost/img/galleries/001/img08.jpg" alt="8" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="9"  />
    <img src="http://localhost/img/galleries/001/img09.jpg" alt="9" class="imgCheck" />

    <input type="checkbox" name="orderID[]" value="10"  />
    <img src="http://localhost/img/galleries/001/img10.jpg" alt="10" class="imgCheck" />

    <input type="hidden" name="galleryID" value="1" />
    <input type="submit" name="remove" value="Remove"  /> This will remove all images checked.
</form>

CI model for processing the form post.

// Start of removing an image functions
    function imgRemove()
    {
        $cnt = 0;
        $id = $this->input->post('galleryID');
        foreach ($_POST['orderID'] as $order)
        {                
            $order = $order - $cnt;
            // get the picture name
            $this->db->select('*');
            $this->db->where("gallery_id = '$id'");
            $this->db->where("`order` = '$order'");
            $this->db->from('gallery');
            $q = $this->db->get();
            if ($q->num_rows != 0)
            {
                $result = $q->result();
                $picture = $result[0]->picture;

                // Get the path and then unlink(delete) the file and it's thumbnail
                $imgPath = $this->imgPath($id);
                $img =  $imgPath . $picture;
                $thumbImg =  $imgPath . 'thumbs/thumb' . $picture;
                if (file_exists($img))
                {
                    unlink($img);
                }
                if (file_exists($thumbImg))
                {
                    unlink($thumbImg);
                }

                // Remove the line from the database
                $this->db->where('gallery_id', $id);
                $this->db->where('order', $order);
                $this->db->delete('gallery');
                // Reorder all images after the deleted one.
                $this->imgOrderCheckRemove($id, $order);
                $cnt++;
            }
        }
    }

Database table layout:
enter image description here

Results from var_dump($images); right before the update_batch.

array(3) {
    [2]=>
    array(5) {
        ["prim_id"]=>
        string(1) "8"
        ["gallery_id"]=>
        string(1) "2"
        ["picture"]=>
        string(21) "002.jpg"
        ["order"]=>
        string(1) "2"
        ["alt_text"]=>
        string(1) "2"
    }
    [10]=>
    array(5) {
        ["prim_id"]=>
        string(2) "16"
        ["gallery_id"]=>
        string(1) "2"
        ["picture"]=>
        string(18) "010.jpg"
        ["order"]=>
        string(2) "10"
        ["alt_text"]=>
        string(2) "10"
    }
    [13]=>
    array(5) {
        ["prim_id"]=>
        string(2) "19"
        ["gallery_id"]=>
        string(1) "2"
        ["picture"]=>
        string(15) "013.jpg"
        ["order"]=>
        string(2) "13"
        ["alt_text"]=>
        string(2) "13"
    }
}
  • 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-06-11T11:16:53+00:00Added an answer on June 11, 2026 at 11:16 am

    Heres something. I might have missed something as i wrote this pretty much on the fly, but it should work quite okay.

    function imgRemove()
        {
            $id = $this->input->post('galleryID');
            $imgPath = $this->imgPath($id);
    
            $this->db->where('gallery_id', $id);
            $result = $this->db-get('gallery');
            $tempArray = $result->result_array();
    
            // reindex $tempArray for more less processing next loop
            foreach($tempArray as $img)
                $images[$img['order']] = $img;
    
            foreach ($_POST['orderID'] as $order)
            {
                $removethese[] = $order;
                if( isset($images[$order]) ) {
                    $unlinkthese[] = $imgPath . $images[$order]['picture'];
                    $unlinkthese[] = $imgPath . 'thumbs/thumb' . $images[$order]['picture'];
    
                }
                // lets keep $images clear, it should contain only images that will exists after cleanup
                unset($images[$order]);
    
            }
            // now lets remove files
            foreach($unlinkthese as $unlink )
                unlink ($unlink);
    
            // and then remove them from database
            $this->db->query("DELETE * FROM gallery where order IN (" . implode(',',$removethese) . " AND gallery_id=$id";
    
            // now lets do some re-ordering. We want to use CIs update_batch to make complex IF WHEN query
    
            for( $i = 1; $i <= count($images); $i++ )
                $images['order'] = $i;
    
            $this->db->update_batch('gallery', $images, 'prim_id'); 
    
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm trying to select an H1 element which is the second-child in its group
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

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.