After delete relation, update field in another table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
8707
Forum Newbie
Posts: 11
Joined: Thu Jan 07, 2010 7:41 pm

After delete relation, update field in another table

Post by 8707 »

Code: Select all

function delete_related_module($module, $crmid, $with_module, $with_crmid) {
        global $adb;
        if(!is_array($with_crmid)) $with_crmid = Array($with_crmid);
        foreach($with_crmid as $relcrmid) {
            
            if($with_module == 'Documents') {
                $adb->pquery("DELETE FROM vtiger_senotesrel WHERE crmid=? AND notesid=?",
                    Array($crmid, $relcrmid));
            } else {
                
                $adb->pquery("DELETE FROM vtiger_crmentityrel WHERE crmid=? AND module=? AND relcrmid=? AND relmodule=?",
                    Array($crmid, $module, $relcrmid, $with_module));   
            }
        }
    }
Above function will delete the relationship between 2 module that store in table vtiger_crmentityrel. But it will only remove the relationship from that table and a related fields id from vtiger_troubletickets will remain in table vtiger_troubletickets. So can i update the field to null or 0 after delete the relationship?

I try to add following code inside else statement but no hope!

Code: Select all

$sql = 'UPDATE vtiger_troubletickets SET servicecontractsid=0 WHERE ticketid=vtiger_crmentityrel.relcrmid';
$this->db->pquery($sql, array($id));
Post Reply