Reputation: 439
Hi guys I have update join
function where it will update the column.
If I try to delete the company it will change the status of the company and as well as if is there any users under that company it will change user status to 0
till now its fine.
But what my problem is if I don't have any users under that company that delete function is not working. Can any one help me how to resolve this issue?
I would like to update the company status if there is no users also. If there is users it has to update from both tables.
Here is my code:
<?php
require('../config.php');
if(!isset($_SESSION['can_access']) || $_SESSION['can_access'] !== true )
header('Location: login.php');
global $DB,$USER;
$userid=$USER->id;
$deletedon = date('Y-m-d H:i:s');
$id = $_GET['id'];;
$DB->execute("UPDATE {ppc_company} mpc
JOIN mdl_user mu ON mpc.cid=mu.skype
SET mpc.deletedby = '$userid',
mpc.deletedon='$deletedon',
mpc.status= '0',
mu.trackforums='0'
WHERE mpc.cid = '$id' and mu.skype='$id'");
header('Location: ' . $_SERVER['HTTP_REFERER']);
?>
Can anyone help me out?
Thanks in advance.
Upvotes: 0
Views: 86
Reputation: 2210
Try using a LEFT JOIN
instead of a JOIN
(JOIN
is defaulting to INNER JOIN
).
This should update the main table even if the join returns null.
Upvotes: 4