btw_nc Posted April 1, 2010 Share Posted April 1, 2010 I have certain photos that need to be deleted from the server. The photos all use the same naming convention: 346986_1.jpg, 346986_2.jpg, etc. The part before the underscore is the ID number in the mySQL dB. There can be anywhere from one to fifteen photos associated with an entry. I have a query set up to find the photos that need deleting. The query just returns the ID field, not the entire filename. I can display the list of ID's using this: while($row = mysqli_fetch_array($resultb)){ echo $row['MLNumber']; echo "<br />";} I have the path to the images set $imgpath = $_SERVER['DOCUMENT_ROOT']."/search/photos/"; How can I append a wildcard (for the underscore and incremental photo number) and the file suffix to the ID numbers, then delete the resulting filenames? Link to comment https://forums.phpfreaks.com/topic/197252-deleting-files-from-list-in-array-sort-of/ Share on other sites More sharing options...
btw_nc Posted April 1, 2010 Author Share Posted April 1, 2010 Can someone tell me if this is on the right track? $imgpath is not being appended as far as I can see. $resultquery = "SELECT IDNumber FROM Table WHERE IndexPhoto='2'"; $resultb = mysqli_query($cxn,$resultquery) or die ("Could not peform query b."); // while ($row = mysqli_fetch_array($resultb)){ // echo $row[MLNumber] . "<br />"; // } $imgpath = $_SERVER['DOCUMENT_ROOT']."/search/photos"; foreach ($resultb as &$value) { $value = $value . $imgpath; } while ($row = mysqli_fetch_array($resultb)){ echo $row[iDNumber] . "<br />"; } unset ($value); mysqli_close($cxn); Link to comment https://forums.phpfreaks.com/topic/197252-deleting-files-from-list-in-array-sort-of/#findComment-1035499 Share on other sites More sharing options...
nafetski Posted April 1, 2010 Share Posted April 1, 2010 My first guess would be take a look at... foreach ($resultb as &$value) { Link to comment https://forums.phpfreaks.com/topic/197252-deleting-files-from-list-in-array-sort-of/#findComment-1035503 Share on other sites More sharing options...
btw_nc Posted April 1, 2010 Author Share Posted April 1, 2010 I was trying to alter the contents of the arry using a reference- &$value. What am I looking for? Link to comment https://forums.phpfreaks.com/topic/197252-deleting-files-from-list-in-array-sort-of/#findComment-1035572 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.