-5

I have a table that has the following example

enter image description here

I need to delete both but the problem is that I have only post id: "PEzQo82KYTLLoXw" as parameter, how to delete both even when it has a comment?

post_id#comment

PEzQo82KYTLLoXw#comment_id

For while this is my query

$p_id = "PEzQo82KYTLLoXw";
$likes = $pdo->prepare('DELETE FROM likes WHERE post_id = :like_p_id');
$likes->bindParam(':like_p_id',  $p_id);
$likes->execute();

since the comment is random, how to also delete all comments linked to it ?

`PEzQo82KYTLLoXw#comment_id`
Community
  • 1
  • 1
Otávio Barreto
  • 1,536
  • 3
  • 16
  • 35

1 Answers1

0

You need a LIKE clause to match the pattern of pid

      $p_id = "PEzQo82KYTLLoXw";
    $likes = $pdo->prepare('DELETE 
          FROM likes WHERE post_id like
            Concat( :like_p_id,'%');
            $likes->bindParam(':like_p_id',  
       $p_id);
     $likes->execute();
Himanshu
  • 3,830
  • 2
  • 10
  • 29