Platon Technologies
neprihlásený Prihlásiť Registrácia
SlovakEnglish
open source software development oslavujeme 10 rokov vývoja otvoreného softvéru! Nedeľa, 29. november 2026
O nás
Magazín
Otvorený softvér
CVS
Služby
Index  »  Projekty  »  phpMyEdit  »  Fórum  »  Multiple delete from different tables

phpMyEdit Configuration     Multiple delete from different tables
Odoslať novú tému   Odpovedať na tému    
 
JammerPro     Založený: 07.12.2006   Príspevky: 33  
Príspevok Zaslal: 2009-11-10 13:15
Návrat hore  Odpovedať s citátom     

I have several tables which are controlled by PHPMyEdit...

In my master table resides the record id which is used to access the information in the other tables.

Here's what I'd like to do... When I delete the master record, I'd like all the associated rows in other tables containing the master record id to be deleted as well. In MySQL I would simply do something like this:

Kód:

<?php
//connect to database
$conn = mysql_connect("localhost", "joeuser", "somepass") or die(mysql_error());
mysql_select_db("testDB",$conn)  or die(mysql_error());

if ($_POST[op] != "delete")  {
    //haven't seen the form, so show it
    $display_block = "<h1>Select an Entry</h1>";

    //get parts of records
    $get_list = "select id, concat_ws(', ', l_name, f_name) as display_name  from master_name order by l_name, f_name";
    $get_list_res = mysql_query($get_list) or die(mysql_error());

    if (mysql_num_rows($get_list_res) < 1) {
        //no records
        $display_block .= "<p><em>Sorry, no records to select!</em></p>";

    } else {
        //has records, so get results and print in a form
        $display_block .= "
        <form method=\"post\" action=\"$_SERVER[PHP_SELF]\">
        <P><strong>Select a Record to Delete:</strong><br>
        <select name=\"sel_id\">
        <option value=\"\">-- Select One --</option>";

        while ($recs = mysql_fetch_array($get_list_res)) {
            $id = $recs['id'];
            $display_name = stripslashes($recs['display_name']);

            $display_block .= "<option value=\"$id\">
                 $display_name</option>";
        }

       $display_block .= "
       </select>
       <input type=\"hidden\" name=\"op\" value=\"delete\">
       <p><input type=\"submit\" name=\"submit\"  value=\"Delete Selected Entry\"></p>
       </FORM>";
    }

} else if ($_POST[op] == "delete") {

   //check for required fields
   if ($_POST[sel_id] == "")  {
       header("Location: delentry.php");
       exit;
   }

   //issue queries
   $del_master = "delete from master_name where id = $_POST[sel_id]";
   mysql_query($del_master);

   $del_address = "delete from address where id = $_POST[sel_id]";
   mysql_query($del_address);

   $del_tel = "delete from telephone where id = $_POST[sel_id]";
   mysql_query($del_tel);

   $del_fax = "delete from fax where id = $_POST[sel_id]";
   mysql_query($del_fax);

   $del_email = "delete from email where id = $_POST[sel_id]";
   mysql_query($del_email);

   $del_note = "delete from personal_notes where id = $_POST[sel_id]";
   mysql_query($del_master);

   $display_block = "<h1>Record(s) Deleted</h1>
   <P>Would you like to
   <a href=\"$_SERVER[PHP_SELF]\">delete another</a>?</p>";
}
?>
<HTML>
<HEAD>
<TITLE>My Records</TITLE>
</HEAD>
<BODY>
<? print $display_block; ?>
</BODY>
</HTML>


Could someone give me some guidance on how to set this up as a trigger so that when I delete the master record, the other stuff stored in the other tables gets deleted too?

Again, thanks for you comments!

 
Odoslať novú tému   Odpovedať na tému    

Copyright © 2002-2006 Platon Group
Stránka používa redakčný systém Metafox
Na začiatok · Odkazový formulár · Prihláška
Upozorniť na chybu na PLATON.SK webstránke · Podmienky použitia · Ochrana osobných údajov