Jump to content

mysql query to find all users have a service and service is cancel


Go to solution Solved by pRieStaKos,

Recommended Posts

  • Solution
\WHMCS\Database\Capsule::table("tblhosting")
    ->join("tblclients", "tblhosting.userid", "=", "tblclients.id")
    ->select("tblclients.email", "tblclients.phonenumber")
    ->whereIn("tblhosting.domainstatus", ["Cancelled", "Terminated"])
    ->where("tblhosting.domain", "<>", "")
    ->whereIn("tblhosting.packageid", [2, 3]) # Add here your product ids
    ->get();

# The above is actually this query

SELECT `tblclients`.`email`, `tblclients`.`phonenumber`
FROM `tblhosting`
INNER JOIN `tblclients` ON `tblhosting`.`userid` = `tblclients`.`id`
WHERE `tblhosting`.`domainstatus` IN ("Cancelled", "Terminated")
  AND `tblhosting`.`domain` <> ""
  AND `tblhosting`.`packageid` IN (2, 3) # Add here your product ids
Edited by pRieStaKos
Link to comment
Share on other sites

5 hours ago, pRieStaKos said:
\WHMCS\Database\Capsule::table("tblhosting")
    ->join("tblclients", "tblhosting.userid", "=", "tblclients.id")
    ->select("tblclients.email", "tblclients.phonenumber")
    ->whereIn("tblhosting.domainstatus", ["Cancelled", "Terminated"])
    ->where("tblhosting.domain", "<>", "")
    ->whereIn("tblhosting.packageid", [2, 3]) # Add here your product ids
    ->get();

# The above is actually this query

SELECT `tblclients`.`email`, `tblclients`.`phonenumber`
FROM `tblhosting`
INNER JOIN `tblclients` ON `tblhosting`.`userid` = `tblclients`.`id`
WHERE `tblhosting`.`domainstatus` IN ("Cancelled", "Terminated")
  AND `tblhosting`.`domain` <> ""
  AND `tblhosting`.`packageid` IN (2, 3) # Add here your product ids

Thank you for your reply, I want  based on service ID, not based on product ID

Link to comment
Share on other sites

On 2/15/2024 at 1:28 PM, pRieStaKos said:
AND `tblhosting`.`id` IN (2, 3) # Add here your service ids

Replace `tblhosting`.`packageid` with `tblhosting`.`id`

It was exactly right, thank you.
Now, if I want to find all the clients in a Group of services, is it possible? Each group includes several different host plans.

Edited by ambaha
Link to comment
Share on other sites

4 hours ago, ambaha said:

It was exactly right, thank you.
Now, if I want to find all the clients in a Group of services, is it possible? Each group includes several different host plans.

\WHMCS\Database\Capsule::table("tblhosting")
  ->join("tblclients", "tblhosting.userid", "=", "tblclients.id")
  ->join("tblproducts", "tblhosting.packageid", "=", "tblproducts.id")
  ->select("tblclients.email", "tblclients.phonenumber")
  ->whereIn("tblhosting.domainstatus", ["Cancelled", "Terminated"])
  ->where("tblhosting.domain", "<>", "")
  ->whereIn("tblproducts.gid", [1, 2]) # Add product group id here
  ->get();
SELECT `tblclients`.`email`, `tblclients`.`phonenumber`, `tblproducts`.`name`
FROM `tblhosting`
INNER JOIN `tblclients` ON `tblhosting`.`userid` = `tblclients`.`id`
INNER JOIN `tblproducts` ON `tblhosting`.`packageid` = `tblproducts`.`id`
WHERE `tblhosting`.`domainstatus` ON ("Cancelled", "Terminated")
  AND `tblhosting`.`domain` <> ""
  AND `tblproducts`.`gid` in (1, 2) # Add product group id here

You can always modify it, as your desire.

Edited by pRieStaKos
Link to comment
Share on other sites

10 hours ago, pRieStaKos said:
\WHMCS\Database\Capsule::table("tblhosting")
  ->join("tblclients", "tblhosting.userid", "=", "tblclients.id")
  ->join("tblproducts", "tblhosting.packageid", "=", "tblproducts.id")
  ->select("tblclients.email", "tblclients.phonenumber")
  ->whereIn("tblhosting.domainstatus", ["Cancelled", "Terminated"])
  ->where("tblhosting.domain", "<>", "")
  ->whereIn("tblproducts.gid", [1, 2]) # Add product group id here
  ->get();
SELECT `tblclients`.`email`, `tblclients`.`phonenumber`, `tblproducts`.`name`
FROM `tblhosting`
INNER JOIN `tblclients` ON `tblhosting`.`userid` = `tblclients`.`id`
INNER JOIN `tblproducts` ON `tblhosting`.`packageid` = `tblproducts`.`id`
WHERE `tblhosting`.`domainstatus` ON ("Cancelled", "Terminated")
  AND `tblhosting`.`domain` <> ""
  AND `tblproducts`.`gid` in (1, 2) # Add product group id here

You can always modify it, as your desire.

Thanks a lot, but I think the correct query is as follows:

 

SELECT `tblclients`.`email`, `tblclients`.`phonenumber`, `tblproducts`.`name`
FROM `tblhosting`
INNER JOIN `tblclients` ON `tblhosting`.`userid` = `tblclients`.`id`
INNER JOIN `tblproducts` ON `tblhosting`.`packageid` = `tblproducts`.`id`
WHERE `tblproducts`.`gid` in (16);

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated