I've created two tables, simplecomments and commentors, and connected them with INNER JOIN
.
- Simplecomments is details of each and every commenter, involving their comment, reg_date, commentorid etc...
- Commentors is the personal info of a commenter with following columns: id, name, email..
I've joined them successfully, however I'm finding it hard to delete from the joined table.
I want to make it like this logic:
If there's last row of a commentor called --let's say A-- then delete both his/her comment details and A himself/herself from the table.
Else if A has commented plenty of times, with different comments, delete his/her comment details, but let his/her personal info remain since A has other comments there.
This is how I've made it:
if (!empty($_POST["delete"]))
{
foreach ($_POST["delete"] as $key => $value)
{
$resultid = $conn->query("SELECT commentorid FROM `simplecomments` WHERE id=".$value);
$rowid = $resultid->fetch_assoc();
$outputdelete = $rowid["name"] . " has been deleted" . "<br>";
$deletedname = $deletedname.$outputdelete;
$RES = mysql_num_rows($resultid);
$counter = 0;
while($row = $RES)
{
//IF IT'S LAST ROW, DELETE COMMENTOR AND HIS/HER COMMENTDETAILS
if(++$counter == $results) {
$resultid = $conn->query("DELETE FROM `commentor`");
}
//ELSE JUST DELETE HIS/HER COMMENTDETAILS, LET HIS/HER INFO REMAIN
else{
$resultid = $conn->query("DELETE FROM `simplecomments` WHERE id=".$value);
}
}
}
}
However code won't work. I get an error:
Warning: mysql_num_rows() expects parameter 1 to be resource [..]...