treehouse : what would you like to learn today?
Web Design Web Development iOS Development

how to unlink multiple images !!

  • Hi ,

    Can you tell me how to unlink multiple images to the same section...

    Like :

    Products -> iphone

    the iphone section have 10 images when i delete this section , all images related to this

    section be deleted ..

    this is my code but but i don't know where the problem

    delete.php

    <form action="inc/delete_ac.php" method="post">
    <table border="1">

    <tr bgcolor="#FF9933">

    <td bgcolor="#e1d8b9"><?php echo $name; ?></td>
    <td><input type="checkbox" name="id[]" value='<?php echo $id; ?>' /></td>
    </tr>
    </table>
    </form>


    delete_ac.php


    <?php

    #### Checkbox Elements .
    $id = $_POST['id'];
    if (isset($_POST['delete']))
    {
    $impid = implode(",", $id);
    $Qdell2 = mysql_query("SELECT * FROM salle WHERE sal_id IN(".$impid.")") or die (mysql_error());
    $Qdell = mysql_query("DELETE FROM salle WHERE sal_id IN(".$impid.")") or die (mysql_error());

    $row2 = mysql_fetch_object($Qdell2);
    $mainOrignal = $row2->mainOrignal;
    $path2 ="../../wed/upload/Sall/";
    @unlink($path2.$mainOrignal);

    //-------------------------------------------------------------------------------------------------------+
    $QdellPic = mysql_query("SELECT * FROM pics WHERE salle_id IN(".$impid.")") or die (mysql_error());
    $QdellPic2 = mysql_query("DELETE FROM pics WHERE salle_id IN(".$impid.")") or die (mysql_error());

    $row = mysql_fetch_object($QdellPic);
    $th = $row->thum;
    $ori = $row->orignal;
    $path ="../../wed/thumb_ori_Img/Sall/";
    @unlink($path.$th);
    @unlink($path.$ori);

    //-------------------------------------------------------------------------------------------------------+
    if (isset($Qdell) && isset($QdellPic2)) {
    redirect_to("../index.php?up=delete");
    }
    }



    but delete one image only

    any help i appreciated ...
  • You need to loop through the records deleting each image in turn.
  • that's right and i delete before unlink ..

    now every thing is OK..

    thanx lyleyboy ..