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

  • Home
  • SEARCH
  • 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 6540445
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:58:49+00:00 2026-05-25T10:58:49+00:00

In my PHP application I have products which have images in 3 sizes –

  • 0

In my PHP application I have products which have images in 3 sizes – big, thumbnails and small thumbnails. Each image is stored in a separate folder:

Images – /gallery
Thumbnails – /gallery/bigthumbs
Small thumbnails – /gallery/thumbs

Each product has its unique ID. The file names of all images of a certain product are the same. The path to the images for the product are being stored in the database with the same ID as the associated product ID.

Each product can have more than 1 image but in the database, where I store the paths and the names of the images for each product, all the images are stored with the same ID, the same as the product ID.

So, if a product with ID 56 has 2 images in the database, those images will be stored like this:

ID->56, image1name, bigthumb1name, thumb1name
ID->56, image2name, bigthumb2name, thumb2name

What I’m trying to do is – delete all the images associated with the product which is being deleted. The code I’ve written is as follows:

$imagename_query = mysql_query("SELECT image FROM gallery WHERE id='$productid'", $connect);

$imagename_result = mysql_fetch_array($imagename_query);


    foreach($imagename_result as $imagename) {

    $bigimage = "../gallery/$imagename";
    unlink($bigimage);

    $picture = "../gallery/bigthumbs/$imagename";
    unlink($picture);

    $thumb = "../gallery/thumbs/$imagename";
    unlink($thumb);

 }

$gallery_query = mysql_query("DELETE FROM gallery WHERE id='$productid'", $connect); 


$query = mysql_query("DELETE FROM products WHERE ID='$productid'", $connect);

The problem is that the code above deletes only 1 image – no difference how many images there are with the same ID.

Could anybody help me figure this out?

Thanks in advance.

  • 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-25T10:58:49+00:00Added an answer on May 25, 2026 at 10:58 am

    Thanks everybody for help. I’ve managed to solve this in the following way:

    $imagename_query = mysql_query("SELECT image FROM gallery WHERE id='$productid'", $connect);
    
        $rows_count = mysql_num_rows($imagename_query);
    
    for($i=0; $i<$rows_count; $i++){
    
        $id = mysql_result($imagename_query, $i, 'image');
    
        $bigimage = "../gallery/$id";
        unlink($bigimage);
    
        $picture = "../gallery/bigthumbs/$id";
        unlink($picture);
    
        $thumb = "../gallery/thumbs/$id";
        unlink($thumb);
    }
    

    Hope this will help somebody else.

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

Sidebar

Related Questions

I have written a PHP application which requires storage of millions of integers between
We have an application, which sells downloadable products. Scenario is: Add product to our
I am doing a very small online store application in PHP. So I have
I have Chinese users of my PHP web application who enter products into our
I am having trouble with modifying a php application to have pagination. My error
I am writing a PHP application that will have the ability to edit settings
I have a PHP application that displays a list of options to a user.
I have a Php application using stream_socket_client(), to get data through tcp from a
I have a PHP application and a need to generate a PDF with the
I have a PHP application that will on occasion have to handle URLs where

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.