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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:18:34+00:00 2026-06-01T22:18:34+00:00

if I do this, it works: $data_array2 = mysql_query(SELECT pic_loc FROM pictures WHERE user_id

  • 0

if I do this, it works:

$data_array2 = mysql_query("SELECT pic_loc FROM pictures WHERE user_id = '".$id."'");
$cell_pictures = mysql_fetch_array($data_array2);
foreach($cell_pictures as $pics_being_deleted) 
{
unlink($pics_being_deleted);
}

Problem being is that the above code is nested meaning it runs a new MySQL query for each time it runs the unlink function so I made the below code to make it not do that:

$the_pics_raw_2 = array();
$data_array2 = mysql_query("SELECT pic_loc FROM pictures WHERE user_id = '".$id."'");
while($cell_pictures = mysql_fetch_array($data_array2))
{
$the_pics_raw = $cell_pictures['pic_loc'];
$the_pics_raw_2[] = $the_pics_raw;
}

$the_pics_raw_3 .= " \"../../". implode("\" , \"../../" ,$the_pics_raw_2)."\"";
$the_pics = array($the_pics_raw_3);

foreach($the_pics as $pics_being_deleted) 
{
unlink($pics_being_deleted);
}

I get this error in return:

Warning: unlink( "../../users/biondizzle/photos/pic_3387677.png" , "../../users/biondizzle/photos/pic_1581185.png") [function.unlink]: No such file or directory

it’s obviously not going to find the "../../users/biondizzle/photos/pic_3387677.png" , "../../users/biondizzle/photos/pic_1581185.png" directory because that’s 2 separate directories running at the same time so the foreach() isn’t “foreaching”.

Any way to get the unlink() to run separately for each directory i have listed in the array, I thought I would get it to work by adding the commas and quotations with the implode()?
Thanks a bunch, hope I explained it well enough
-Mike

  • 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-01T22:18:35+00:00Added an answer on June 1, 2026 at 10:18 pm

    I think this is what you want to do:

    while($cell_pictures = mysql_fetch_array($data_array2)) {
        $the_pics_raw = $cell_pictures['pic_loc'];
        $the_pics[] = "../../" . $the_pics_raw;
    }
    
    foreach($the_pics as $pics_being_deleted) {
        unlink($pics_being_deleted);
    }
    

    You will notice I have removed the $the_pics_raw_3 .= " \"../../". implode("\" , \"../../" ,$the_pics_raw_2)."\""; line as it was converting the array into a string, which was making it impossible to then foreach over.

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

Sidebar

Related Questions

I have this PHP code: $result = mysql_query(SELECT banner FROM banners ) or die(mysql_error());
<?php $con= mysql_connect(localhost,root,mysql); mysql_select_db(Db_name,$con); $res=mysql_query(select *from table_name); mysql_close($con); // closing connection before fetching contents.
(This question is following on from my previous problem which has been fixed (Here)
This works fine: $.getJSON(http://localhost:59396/xxxWeb/ CarouselHandler.ashx?action=getproducts&ids= + ids, function(data) { carousel.size(allProductIDs.length); if (numberOfImagesLeftToShow < numberOfImagesToDisplay)
This works fine: var vm = {}; $.getJSON('file.json', function (data) { vm.objects = data;
Im writing a form to post data off to paypal, and this works fine,
Using Java sockets, I made a simple server. This works because it sends data
I'm attempting to copy the database located, as an example, in: /data/data/com.x.x.x/databases/mydb.db This works
This syntax works in FF <input data-bind=checked: isRequest, attr: { name: 'id_' + id
I am having trouble constructing a jqGrid TreeGrid using local data. This method works

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.