Trying to delete from table.2 if no row count exist or < than one in table.1. using a variable ($group). I think the problem is after I delete the row in table.1 there’s no variable to go by to delete in table.2 so it doesn not delete the row. I don’t know if this makes sense. Here’s the code.
$q = mysql_query("SELECT `group name` FROM `group` WHERE cid = '$id'") or die(mysql_error());
list($group) = mysql_fetch_row($q);
$n = mysql_query("select count(`group name`) as total from `group` WHERE user_id
= '$_SESSION[user_id]' AND cid = '$id' ");
$r = mysql_fetch_array($n);
if($r['total'] = 0 ) {
mysql_query("DELETE FROM `group log`
WHERE `group name`='$group'
") or die(mysql_error());
}
I’ve also tried this but it just deletes the row after user deletes all rows:
mysql_query("DELETE FROM `group log`
WHERE NOT EXISTS(SELECT NULL
FROM `group` g
WHERE g.`group name` = `group name`)");
show create table yourtableoutput? You cannot have spaces in MySQL column names...if($r['total'] = 0 )should have==group(idint(255) NOT NULL AUTO_INCREMENT,group namevarchar(255) NOT NULL,createddate NOT NULL DEFAULT '0000-00-00',photovarchar(255) NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ; CREATE TABLE IF NOT EXISTSgroup log(idint(255) NOT NULL AUTO_INCREMENT,group namevarchar(255) CHARACTER SET utf8 NOT NULL,createddate NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=7 ;