Skip to content

Instantly share code, notes, and snippets.

@BJIAST
Created March 23, 2020 19:31
Show Gist options
  • Select an option

  • Save BJIAST/f98c128f871c61676fd39980890e23ba to your computer and use it in GitHub Desktop.

Select an option

Save BJIAST/f98c128f871c61676fd39980890e23ba to your computer and use it in GitHub Desktop.
public function subscribe($product_id, $user) {
$query = $this->db->query("SELECT subscribes FROM " . DB_PREFIX . "product WHERE product_id = '" . (int)$product_id . "'");
if ($query->num_rows && $query->row['subscribes'] != '' ) {
$subscribes = json_decode($query->row['subscribes']);
$user = json_decode($user);
$key = array_search($user->email, array_column($subscribes, 'email'));
if(false == $key) {
return false;
}
array_push($subscribes, $user);
$subscribes = json_encode($subscribes);
} else {
$user = json_decode($user);
$subscribes = json_encode(array($user));
}
$this->db->query("UPDATE " . DB_PREFIX . "product SET subscribes = '$subscribes' WHERE product_id = '" . (int)$product_id . "'");
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment