lovephp Posted March 16, 2015 Share Posted March 16, 2015 hey all, my code here works alright but just that when it comes to deleting a posts its unable to delete all images off the uploads/images folder, it unlink just one image related to the topic whereas i want all images unlinked when i delete the topic $cid =$_REQUEST['cid']; $tid =$_REQUEST['tid']; if(isset($_SESSION['signed_in']) && $_SESSION['signed_in'] == true) { $sql="SELECT * FROM posts WHERE post_topic ='".$tid."'"; $result = mysql_query($sql); if(!$result){ }else{ while($row = mysql_fetch_array($result)){ if (mysql_num_rows($result)) { if(!unlink($row['post_img'])){ } } // sending query mysql_query("DELETE FROM topics WHERE topic_id = '".$tid."' AND topic_cat = '".$cid."'")or die(mysql_error()); mysql_query("DELETE FROM posts WHERE post_topic = '".$tid."'")or die(mysql_error()); $result= mysql_query($sql); } header("Location: category.php?id=".$cid.""); } }else{ header("Location: category.php?id=".$cid.""); } appreciate you help. Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/ Share on other sites More sharing options...
lovephp Posted March 16, 2015 Author Share Posted March 16, 2015 Any help? Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/#findComment-1508210 Share on other sites More sharing options...
ginerjm Posted March 16, 2015 Share Posted March 16, 2015 Perhaps because you re-use the $result var inside your loop, thus obviating your check for num rows inside that same loop? Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/#findComment-1508211 Share on other sites More sharing options...
lovephp Posted March 16, 2015 Author Share Posted March 16, 2015 I dunno but do you think it has to be done with a for loop? Been trying for a long time but unable to get the results it would delete only one image Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/#findComment-1508212 Share on other sites More sharing options...
ginerjm Posted March 16, 2015 Share Posted March 16, 2015 Why not address what I suggested you do before asking more questions? Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/#findComment-1508232 Share on other sites More sharing options...
Solution lovephp Posted March 17, 2015 Author Solution Share Posted March 17, 2015 i got it sorted code works fine issue was my sql query thanks for your time appreciate it Quote Link to comment https://forums.phpfreaks.com/topic/295271-unable-to-unlink-all-images-related-to-topic-id/#findComment-1508332 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.